UserManager.java revision e4afaa3a3d7c2885b82fe43f51bcf04e036f7462
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
18a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackbornimport android.app.ActivityManagerNative;
19258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.Context;
20258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.pm.UserInfo;
2127bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkeyimport android.content.res.Resources;
226794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport android.graphics.Bitmap;
234f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.Canvas;
244f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.Bitmap.Config;
254f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.Rect;
264f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.drawable.BitmapDrawable;
274f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.drawable.Drawable;
281e9c21871e81642669079cd290ef47818a3165bdAmith Yamasaniimport android.provider.Settings;
29258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.util.Log;
30258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
316794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport com.android.internal.R;
326794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
334f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport java.util.ArrayList;
34258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport java.util.List;
35258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
36258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/**
37258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Manages users and user details on a multi-user system.
38258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */
39258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipublic class UserManager {
40258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
41258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private static String TAG = "UserManager";
42258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private final IUserManager mService;
43258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private final Context mContext;
44258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
45e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
4671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Key for user restrictions. Specifies if a user is disallowed from adding and removing
4771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * accounts.
4871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
4971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * <p/>
50e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * Type: Boolean
51e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
52e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
53e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
5471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
55e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
56e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
5771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Key for user restrictions. Specifies if a user is disallowed from changing Wi-Fi
5871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * access points.
5971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
6071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * <p/>
61e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * Type: Boolean
62e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
63e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
64e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
6571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi";
66e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
67e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
6871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Key for user restrictions. Specifies if a user is disallowed from installing applications.
6971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
7071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * <p/>
71e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * Type: Boolean
72e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
73e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
74e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
7571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_INSTALL_APPS = "no_install_apps";
76e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
77e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
7871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Key for user restrictions. Specifies if a user is disallowed from uninstalling applications.
7971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
8071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * <p/>
81e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * Type: Boolean
82e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
83e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
84e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
8571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
86e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
8771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
8871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Key for user restrictions. Specifies if a user is disallowed from toggling location sharing.
8971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
9071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * <p/>
916794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     * Type: Boolean
926794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     * @see #setUserRestrictions(Bundle)
936794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     * @see #getUserRestrictions()
946794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
9571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_SHARE_LOCATION = "no_share_location";
966794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
97a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
98a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Key for user restrictions. Specifies if a user is disallowed from enabling the
99a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * "Unknown Sources" setting, that allows installation of apps from unknown sources.
100a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * The default value is <code>false</code>.
101a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * <p/>
102a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Type: Boolean
103a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
104a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
105a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
106a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
107a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
108a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
109a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Key for user restrictions. Specifies if a user is disallowed from configuring bluetooth.
110a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * The default value is <code>false</code>.
111a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * <p/>
112a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Type: Boolean
113a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
114a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
115a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
116a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
117a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
118a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
119a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Key for user restrictions. Specifies if a user is disallowed from transferring files over
120a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * USB. The default value is <code>false</code>.
121a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * <p/>
122a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Type: Boolean
123a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
124a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
125a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
126a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
127a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
128b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    /**
129b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * Key for user restrictions. Specifies if a user is disallowed from configuring user
130b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * credentials. The default value is <code>false</code>.
131b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * <p/>
132b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * Type: Boolean
133b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #setUserRestrictions(Bundle)
134b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
135b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
136b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
137b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
138b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    /**
139b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * Key for user restrictions. Specifies if a user is disallowed from removing users.
140b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * The default value is <code>false</code>.
141b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * <p/>
142b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * Type: Boolean
143b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #setUserRestrictions(Bundle)
144b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
145b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
146b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_REMOVE_USER = "no_remove_user";
147b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
148d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
149d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from enabling or
150d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * accessing debugging features. The default value is <code>false</code>.
151d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p/>
152d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Type: Boolean
153d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
154d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
155d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
156d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
157d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
158d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
159d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from configuring VPN.
160d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * The default value is <code>false</code>.
161d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p/>
162d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Type: Boolean
163d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
164d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
165d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
166d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_VPN = "no_config_vpn";
167d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
168d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
169d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from configuring Tethering
170d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * & portable hotspots. The default value is <code>false</code>.
171d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p/>
172d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Type: Boolean
173d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
174d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
175d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
176d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering";
177d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
178d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
179d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from factory resetting
180d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * from Settings.
181d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * The default value is <code>false</code>.
182d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p>
183d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
184d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
185d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
186d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_FACTORY_RESET = "no_factory_reset";
187d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
188d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
189d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from adding new users and
190d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * profiles. The default value is <code>false</code>.
191d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p>
192d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Type: Boolean
193d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
194d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
195d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
196d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_ADD_USER = "no_add_user";
197d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
198d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
199d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from disabling application
200d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * verification. The default value is <code>false</code>.
201d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p>
202d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Type: Boolean
203d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
204d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
205d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
206d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps";
207d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
208d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
209d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from configuring cell
210d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * broadcasts. The default value is <code>false</code>.
211d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p>
212d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Type: Boolean
213d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
214d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
215d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
216d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts";
217d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
218d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
219d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from configuring mobile
220d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * networks. The default value is <code>false</code>.
221d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p>
222d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Type: Boolean
223d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
224d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
225d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
226d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks";
227d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
228d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
22936fbc8d6453da438a8ab83352ff1bcfcba5f25b5Julia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from controlling
230d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * applications in Settings. The default value is <code>false</code>.
231d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p>
232d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Type: Boolean
233d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
234d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
235d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
23636fbc8d6453da438a8ab83352ff1bcfcba5f25b5Julia Reynolds    public static final String DISALLOW_APPS_CONTROL = "no_control_apps";
237d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
238394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
239394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * Key for user restrictions. Specifies if a user is disallowed from mounting
240394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * physical external media. The default value is <code>false</code>.
241394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * <p/>
242394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * Type: Boolean
243394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
244394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
245394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
246394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
247394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
248394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
249394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * Key for user restrictions. Specifies if a user is disallowed from adjusting microphone
250394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * volume.
251394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * The default value is <code>false</code>.
252394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * <p/>
253394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * Type: Boolean
254394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
255394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
256394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
257394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
258394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
259394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
260394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * Key for user restrictions. Specifies if a user is disallowed from adjusting the master
261394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * volume.
262394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * The default value is <code>false</code>.
263394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * <p/>
264394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * Type: Boolean
265394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
266394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
267394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
268394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume";
269394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
2709f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani    /**
2719f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * Key for user restrictions. Specifies that the user is not allowed to send or receive
2729f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * phone calls or text messages. Emergency calls may still be permitted.
2739f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * The default value is <code>false</code>.
2749f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * <p/>
2759f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * Type: Boolean
2769f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * @see #setUserRestrictions(Bundle)
2779f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * @see #getUserRestrictions()
2789f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     */
2799f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani    public static final String DISALLOW_TELEPHONY = "no_telephony";
2809f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani
281655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
282655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
283655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
284655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2;
285655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
286655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_SUCCESS = -1;
287655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
28827db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    private static UserManager sInstance = null;
28927db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani
2907e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /** @hide */
29127db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    public synchronized static UserManager get(Context context) {
29227db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        if (sInstance == null) {
29327db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani            sInstance = (UserManager) context.getSystemService(Context.USER_SERVICE);
29427db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        }
29527db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        return sInstance;
29627db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    }
297a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
298258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /** @hide */
299258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserManager(Context context, IUserManager service) {
300258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        mService = service;
301258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        mContext = context;
302258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
303258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
304258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
305258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns whether the system supports multiple users.
3061a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @return true if multiple users can be created by user, false if it is a single user device.
307e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @hide
308258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
3094673e7ea8d1f869910a9c0f9c211d4d27ad50b41Jeff Sharkey    public static boolean supportsMultipleUsers() {
3101a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        return getMaxSupportedUsers() > 1
3111a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                && SystemProperties.getBoolean("fw.show_multiuserui",
3121a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));
313258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
314258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
3156794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    /**
316be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns the user handle for the user that the calling process is running on.
317be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     *
318258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the user handle of the user making this call.
319258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
3206794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
321258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public int getUserHandle() {
32279af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn        return UserHandle.myUserId();
323258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
324258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
325258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
3268832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * Returns the user name of the user making this call.  This call is only
3278832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * available to applications on the system image; it requires the
3288832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * MANAGE_USERS permission.
329258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the user name
330258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
331258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public String getUserName() {
332258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
333258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(getUserHandle()).name;
334258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
335258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user name", re);
336258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return "";
337258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
338258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
339258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
340e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill   /**
341e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * Used to determine whether the user making this call is subject to
342e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * teleportations.
343a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @return whether the user making this call is a goat
344e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     */
345e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    public boolean isUserAGoat() {
346e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill        return false;
347e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    }
348df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
349df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
350e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * Used to check if the user making this call is linked to another user. Linked users may have
35146bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani     * a reduced number of available apps, app restrictions and account restrictions.
352e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * @return whether the user making this call is a linked user
3532555dafce87e60fae28d71913730abf73e40fcd7Amith Yamasani     * @hide
354df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
355e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani    public boolean isLinkedUser() {
356df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
35771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani            return mService.isRestricted();
358df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
35946bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani            Log.w(TAG, "Could not check if user is limited ", re);
360df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            return false;
361df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
362df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
363df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
364258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
3651e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * Checks if the calling app is running as a guest user.
3661e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @return whether the caller is a guest user.
3671e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @hide
3681e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     */
3691e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    public boolean isGuestUser() {
3701e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        UserInfo user = getUserInfo(UserHandle.myUserId());
3711e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        return user != null ? user.isGuest() : false;
3721e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    }
3731e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani
3741e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    /**
375a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running.  This means that
376a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * the user is in the "started" state, not "stopped" -- it is currently
377a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * allowed to run code through scheduled alarms, receiving broadcasts,
378a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * etc.  A started user may be either the current foreground user or a
379a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * background user; the result here does not distinguish between the two.
380a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
381a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
382a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunning(UserHandle user) {
383a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
384a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return ActivityManagerNative.getDefault().isUserRunning(
385a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn                    user.getIdentifier(), false);
386a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        } catch (RemoteException e) {
387a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return false;
388a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
389a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
390a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
391a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    /**
392a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running <em>or</em> stopping.
393a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * This is like {@link #isUserRunning(UserHandle)}, but will also return
394a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * true if the user had been running but is in the process of being stopped
395a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * (but is not yet fully stopped, and still running some code).
396a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
397a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
398a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunningOrStopping(UserHandle user) {
399a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
400a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return ActivityManagerNative.getDefault().isUserRunning(
401a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn                    user.getIdentifier(), true);
402a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        } catch (RemoteException e) {
403a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return false;
404a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
405a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
406a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
407a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    /**
408258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the UserInfo object describing a specific user.
4091952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
410258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user handle of the user whose information is being requested.
411258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for a specific user.
412258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
413b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
414258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserInfo getUserInfo(int userHandle) {
415258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
416258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(userHandle);
417258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
418258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user info", re);
419258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
420258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
421258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
422258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
42371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
42471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on this user.
42571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
42671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
427e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions() {
428e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        return getUserRestrictions(Process.myUserHandle());
429e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
430e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
43171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
43271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
43371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
43471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
43571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
436e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions(UserHandle userHandle) {
437e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        try {
438e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            return mService.getUserRestrictions(userHandle.getIdentifier());
439e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        } catch (RemoteException re) {
440e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            Log.w(TAG, "Could not get user restrictions", re);
441e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            return Bundle.EMPTY;
442e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        }
443e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
444e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
44571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
44671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets all the user-wide restrictions for this user.
447be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
44871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param restrictions the Bundle containing all the restrictions.
44971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
450e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions) {
451e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        setUserRestrictions(restrictions, Process.myUserHandle());
452e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
453e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
45471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
45571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets all the user-wide restrictions for the specified user.
456be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
45771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param restrictions the Bundle containing all the restrictions.
45871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the UserHandle of the user for whom to set the restrictions.
45971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
460e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
461e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        try {
462e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            mService.setUserRestrictions(restrictions, userHandle.getIdentifier());
463e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        } catch (RemoteException re) {
464e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            Log.w(TAG, "Could not set user restrictions", re);
465e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        }
466e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
467e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
46871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
46971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction.
470be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
47171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
47271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
47371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
47471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public void setUserRestriction(String key, boolean value) {
47571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        Bundle bundle = getUserRestrictions();
47671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        bundle.putBoolean(key, value);
47771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        setUserRestrictions(bundle);
47871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    }
47971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani
48071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
48171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @hide
48271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction on a specific user.
483be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
48471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
48571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
48671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the user whose restriction is to be changed.
48771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
4886794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
4896794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall        Bundle bundle = getUserRestrictions(userHandle);
4906794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall        bundle.putBoolean(key, value);
4916794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall        setUserRestrictions(bundle, userHandle);
4926794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    }
4936794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
494258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
495a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Returns whether the current user has been disallowed from performing certain actions
496a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * or setting certain settings.
4972b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     *
4982b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     * @param restrictionKey The string key representing the restriction.
4992b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     * @return {@code true} if the current user has the given restriction, {@code false} otherwise.
500a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
501a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public boolean hasUserRestriction(String restrictionKey) {
502b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie        return hasUserRestriction(restrictionKey, Process.myUserHandle());
503b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    }
504b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie
505b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    /**
506b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @hide
507b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * Returns whether the given user has been disallowed from performing certain actions
508b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * or setting certain settings.
509b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param restrictionKey the string key representing the restriction
510b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
511b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     */
512b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
513b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie        return getUserRestrictions(userHandle).getBoolean(restrictionKey, false);
514a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    }
515a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
516a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
51733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the serial number for a user.  This is a device-unique
518b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * number assigned to that user; if the user is deleted and then a new
519b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * user created, the new users will not be given the same serial number.
52033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param user The user whose serial number is to be retrieved.
521b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * @return The serial number of the given user; returns -1 if the
522b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * given UserHandle does not exist.
52333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getUserForSerialNumber(long)
52433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
52533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public long getSerialNumberForUser(UserHandle user) {
52633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return getUserSerialNumber(user.getIdentifier());
52733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
52833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
52933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
53033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the user associated with a serial number previously
53133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * returned by {@link #getSerialNumberForUser(UserHandle)}.
53233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param serialNumber The serial number of the user that is being
53333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * retrieved.
53433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @return Return the user associated with the serial number, or null
53533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * if there is not one.
53633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getSerialNumberForUser(UserHandle)
53733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
53833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public UserHandle getUserForSerialNumber(long serialNumber) {
53933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        int ident = getUserHandle((int)serialNumber);
54033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return ident >= 0 ? new UserHandle(ident) : null;
54133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
54233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
54333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
544258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Creates a user with the specified name and options.
5451952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
546258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
547258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the user's name
548258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param flags flags that identify the type of user and other properties.
549258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @see UserInfo
550258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
551258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for the created user, or null if the user could not be created.
552258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
553258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
554258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserInfo createUser(String name, int flags) {
555258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
556258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.createUser(name, flags);
557258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
558258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not create a user", re);
559258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
560258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
561258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
562258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
563258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
5641e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * Creates a guest user and configures it.
5651e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @param context an application context
5661e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @param name the name to set for the user
5671e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @hide
5681e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     */
5691e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    public UserInfo createGuest(Context context, String name) {
5701e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        UserInfo guest = createUser(name, UserInfo.FLAG_GUEST);
5711e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        if (guest != null) {
5721e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani            Settings.Secure.putStringForUser(context.getContentResolver(),
5731e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani                    Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
5741e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        }
5751e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        return guest;
5761e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    }
5771e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani
5781e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    /**
5792a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Creates a user with the specified name and options as a profile of another user.
580a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
581a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     *
582a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @param name the user's name
583a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @param flags flags that identify the type of user and other properties.
584a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @see UserInfo
5852a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @param userHandle new user will be a profile of this use.
586a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     *
587a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @return the UserInfo object for the created user, or null if the user could not be created.
588a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @hide
589a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     */
5902a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy    public UserInfo createProfileForUser(String name, int flags, int userHandle) {
591a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        try {
5922a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy            return mService.createProfileForUser(name, flags, userHandle);
593a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        } catch (RemoteException re) {
594a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            Log.w(TAG, "Could not create a user", re);
595a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            return null;
596a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        }
597a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    }
598a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy
599a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    /**
600df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Sets the user as enabled, if such an user exists.
601df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
602df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Note that the default is true, it's only that managed profiles might not be enabled.
603df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     *
604df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * @param userHandle the id of the profile to enable
605df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * @hide
606df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     */
607df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    public void setUserEnabled(int userHandle) {
608df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        try {
609df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina            mService.setUserEnabled(userHandle);
610df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        } catch (RemoteException e) {
611df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina            Log.w(TAG, "Could not enable the profile", e);
612df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        }
613df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    }
614df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina
615df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    /**
616b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * Return the number of users currently created on the device.
617b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
618b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    public int getUserCount() {
619b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        List<UserInfo> users = getUsers();
620b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        return users != null ? users.size() : 1;
621b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    }
622b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn
623b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    /**
624258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns information for all users on this device.
6251952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
626258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the list of users that were created.
627258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
628258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
629258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public List<UserInfo> getUsers() {
630258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
631920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(false);
632920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        } catch (RemoteException re) {
633920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            Log.w(TAG, "Could not get user list", re);
634920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return null;
635920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        }
636920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    }
637920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani
638920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    /**
6392a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Returns list of the profiles of userHandle including
6402a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * userHandle itself.
641385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina     * Note that it this returns both enabled and not enabled profiles. See
642385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina     * {@link #getUserProfiles()} if you need only the enabled ones.
6434f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *
6442a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
6452a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @param userHandle profiles of this user will be returned.
6462a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @return the list of profiles.
6472a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @hide
6482a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     */
6492a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy    public List<UserInfo> getProfiles(int userHandle) {
650a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        try {
651385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            return mService.getProfiles(userHandle, false /* enabledOnly */);
652a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        } catch (RemoteException re) {
653a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            Log.w(TAG, "Could not get user list", re);
654a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            return null;
655a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        }
656a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    }
657a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy
658a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    /**
659be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns a list of UserHandles for profiles associated with the user that the calling process
660be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * is running on, including the user itself.
6614f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *
6624f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * @return A non-empty list of UserHandles associated with the calling user.
6634f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     */
6644f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    public List<UserHandle> getUserProfiles() {
6654f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        ArrayList<UserHandle> profiles = new ArrayList<UserHandle>();
666385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        List<UserInfo> users = new ArrayList<UserInfo>();
667385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        try {
668f2e7b3f56ae0ea9f49b5c50413b9be71d5249d6dAlexandra Gherghina            users = mService.getProfiles(UserHandle.myUserId(), true /* enabledOnly */);
669385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        } catch (RemoteException re) {
670385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            Log.w(TAG, "Could not get user list", re);
671385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            return null;
672385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        }
6734f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        for (UserInfo info : users) {
6744f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            UserHandle userHandle = new UserHandle(info.id);
6754f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            profiles.add(userHandle);
6764f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        }
6774f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        return profiles;
6784f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
6794f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
6807dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani    /**
681be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns the parent of the profile which this method is called from
682be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * or null if called from a user that is not a profile.
683be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     *
684be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * @hide
685be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     */
686be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    public UserInfo getProfileParent(int userHandle) {
687be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        try {
688be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            return mService.getProfileParent(userHandle);
689be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        } catch (RemoteException re) {
690be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            Log.w(TAG, "Could not get profile parent", re);
691be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            return null;
692be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        }
693be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    }
694be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel
695be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    /**
6967dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * If the target user is a managed profile of the calling user or the caller
6977dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * is itself a managed profile, then this returns a badged copy of the given
6987dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * icon to be able to distinguish it from the original icon.
6997dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * <P>
7007dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * If the original drawable is not a BitmapDrawable, then the original
7017dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * drawable is returned.
7027dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * </P>
7037dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     *
7047dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * @param icon The icon to badge.
7057dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * @param user The target user.
7067dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * @return A drawable that combines the original icon and a badge as
7077dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     *         determined by the system.
7087dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     */
7094f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    public Drawable getBadgedDrawableForUser(Drawable icon, UserHandle user) {
7104f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        int badgeResId = getBadgeResIdForUser(user.getIdentifier());
7114f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        if (badgeResId == 0) {
7124f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            return icon;
7134f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        } else {
7144f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            Drawable badgeIcon = mContext.getPackageManager()
7154f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani                    .getDrawable("system", badgeResId, null);
7164f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            return getMergedDrawable(icon, badgeIcon);
7174f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        }
7184f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
7194f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
720701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    /**
721701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * If the target user is a managed profile of the calling user or the caller
722f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * is itself a managed profile, then this returns a copy of the label with
723f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * badging for accessibility services like talkback. E.g. passing in "Email"
724f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * and it might return "Work Email" for Email in the work profile.
725f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     *
726f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @param label The label to change.
727f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @param user The target user.
728f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @return A label that combines the original label and a badge as
729f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     *         determined by the system.
730f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     */
731f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy    public String getBadgedLabelForUser(String label, UserHandle user) {
732f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy        UserInfo userInfo = getUserIfProfile(user.getIdentifier());
733f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy        if (userInfo != null && userInfo.isManagedProfile()) {
734f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy            return Resources.getSystem().getString(
735f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy                    R.string.managed_profile_label_badge, label);
736f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy        }
737f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy        return label;
738f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy    }
739f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy
740f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy    /**
741f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * If the target user is a managed profile of the calling user or the caller
742701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * is itself a managed profile, then this returns a drawable to use as a small
743701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * icon to include in a view to distinguish it from the original icon.
744701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     *
745701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * @param user The target user.
746701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * @return the drawable or null if no drawable is required.
747701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * @hide
748701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     */
749701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    public Drawable getBadgeForUser(UserHandle user) {
750701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        UserInfo userInfo = getUserIfProfile(user.getIdentifier());
751701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        if (userInfo != null && userInfo.isManagedProfile()) {
752701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy            return Resources.getSystem().getDrawable(
753701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy                    com.android.internal.R.drawable.ic_corp_badge);
754701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        }
755701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        return null;
756701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    }
757701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy
7584f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    private int getBadgeResIdForUser(int userHandle) {
7594f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        // Return the framework-provided badge.
760701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        UserInfo userInfo = getUserIfProfile(userHandle);
761701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        if (userInfo != null && userInfo.isManagedProfile()) {
762701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy            return com.android.internal.R.drawable.ic_corp_icon_badge;
763701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        }
764701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        return 0;
765701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    }
766701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy
767701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    /**
768701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * @return UserInfo for userHandle if it exists and is a profile of the current
769701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     *         user or null.
770701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     */
771701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    private UserInfo getUserIfProfile(int userHandle) {
772be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        List<UserInfo> userProfiles = getProfiles(getUserHandle());
7735abdbb656063160ff8df2306bd01feba0714d4c1Amith Yamasani        for (UserInfo user : userProfiles) {
774701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy            if (user.id == userHandle) {
775701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy                return user;
7764f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            }
7774f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        }
778701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        return null;
7794f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
7804f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
7814f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    private Drawable getMergedDrawable(Drawable icon, Drawable badge) {
7824f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        final int width = icon.getIntrinsicWidth();
7834f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        final int height = icon.getIntrinsicHeight();
7844f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
7854f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        Canvas canvas = new Canvas(bitmap);
7864f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        icon.setBounds(0, 0, width, height);
7874f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        icon.draw(canvas);
7884f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        badge.setBounds(0, 0, width, height);
7894f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        badge.draw(canvas);
7904f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        BitmapDrawable merged = new BitmapDrawable(bitmap);
7914f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        if (icon instanceof BitmapDrawable) {
7924f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            merged.setTargetDensity(((BitmapDrawable) icon).getBitmap().getDensity());
7934f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        }
7944f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        return merged;
7954f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
7964f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
7974f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    /**
7984f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * Returns information for all users on this device. Requires
7994f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * {@link android.Manifest.permission#MANAGE_USERS} permission.
800394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     *
8014f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * @param excludeDying specify if the list should exclude users being
8024f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *            removed.
803920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @return the list of users that were created.
804920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @hide
805920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     */
806920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    public List<UserInfo> getUsers(boolean excludeDying) {
807920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        try {
808920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(excludeDying);
809258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
810258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user list", re);
811258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
812258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
813258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
814258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
815258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
816258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Removes a user and all associated data.
8171952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
818258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the integer handle of the user, where 0 is the primary user.
819258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
820258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
821258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public boolean removeUser(int userHandle) {
822258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
823258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.removeUser(userHandle);
824258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
825258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not remove user ", re);
826258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return false;
827258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
828258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
829258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
830258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
831258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Updates the user's name.
8321952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
833258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
834258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user's integer handle
835258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the new name for the user
836258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
837258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
838258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public void setUserName(int userHandle, String name) {
839258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
840258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            mService.setUserName(userHandle, name);
841258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
842258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not set the user name ", re);
843258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
844258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
845258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
846258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
847e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * Sets the user's photo.
848258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user for whom to change the photo.
849e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @param icon the bitmap to set as the photo.
850258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
851258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
852e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani    public void setUserIcon(int userHandle, Bitmap icon) {
853258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
854e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani            mService.setUserIcon(userHandle, icon);
855258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
856258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not set the user icon ", re);
857258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
858258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
859258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
860258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
8613b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * Returns a file descriptor for the user's photo. PNG data can be read from this file.
8623b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @param userHandle the user whose photo we want to read.
863e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
8643b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @hide
8653b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     */
866e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani    public Bitmap getUserIcon(int userHandle) {
8673b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        try {
8683b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani            return mService.getUserIcon(userHandle);
8693b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        } catch (RemoteException re) {
870e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani            Log.w(TAG, "Could not get the user icon ", re);
8713b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani            return null;
8723b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        }
8733b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    }
8743b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani
8753b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    /**
876258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the maximum number of users that can be created on this device. A return value
877258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * of 1 means that it is a single user device.
878258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
879a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @return a value greater than or equal to 1
880258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
88127bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey    public static int getMaxSupportedUsers() {
882ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        // Don't allow multiple users on certain builds
883ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        if (android.os.Build.ID.startsWith("JVP")) return 1;
88427bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey        return SystemProperties.getInt("fw.max_users",
88527bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey                Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
886258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
8872a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
8882a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
8891a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * Returns true if the user switcher should be shown, this will be if there
8901a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * are multiple users that aren't managed profiles.
8911a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @hide
8921a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @return true if user switcher should be shown.
8931a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     */
8941a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    public boolean isUserSwitcherEnabled() {
8951a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        List<UserInfo> users = getUsers(true);
8961a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        if (users == null) {
8971a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy           return false;
8981a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        }
8991a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        int switchableUserCount = 0;
9001a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        for (UserInfo user : users) {
9011a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy            if (user.supportsSwitchTo()) {
9021a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                ++switchableUserCount;
9031a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy            }
9041a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        }
905a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani        final boolean guestEnabled = Settings.Global.getInt(mContext.getContentResolver(),
906a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani                Settings.Global.GUEST_USER_ENABLED, 0) == 1;
907a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani        return switchableUserCount > 1 || guestEnabled;
9081a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    }
9091a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy
9101a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    /**
9112a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a serial number on this device for a given userHandle. User handles can be recycled
9122a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * when deleting and creating users, but serial numbers are not reused until the device is wiped.
9132a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userHandle
9142a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return a serial number associated with that user, or -1 if the userHandle is not valid.
9152a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
9162a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
9172a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    public int getUserSerialNumber(int userHandle) {
9182a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
9192a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserSerialNumber(userHandle);
9202a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
9212a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            Log.w(TAG, "Could not get serial number for user " + userHandle);
9222a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
9232a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        return -1;
9242a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
9252a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
9262a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
9272a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a userHandle on this device for a given user serial number. User handles can be
9282a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * recycled when deleting and creating users, but serial numbers are not reused until the device
9292a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is wiped.
9302a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userSerialNumber
9312a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return the userHandle associated with that user serial number, or -1 if the serial number
9322a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is not valid.
9332a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
9342a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
9352a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    public int getUserHandle(int userSerialNumber) {
9362a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
9372a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserHandle(userSerialNumber);
9382a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
9392a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            Log.w(TAG, "Could not get userHandle for user " + userSerialNumber);
9402a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
9412a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        return -1;
9422a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
9436794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
9447e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /**
9457e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * Returns a Bundle containing any saved application restrictions for this user, for the
9467e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * given package name. Only an application with this package name can call this method.
9477e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * @param packageName the package name of the calling application
9487e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * @return a Bundle with the restrictions as key/value pairs, or null if there are no
9497e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * saved restrictions. The values can be of type Boolean, String or String[], depending
9507e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * on the restriction type, as defined by the application.
9517e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     */
9527e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName) {
9537e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        try {
9547e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictions(packageName);
9557e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        } catch (RemoteException re) {
9567e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            Log.w(TAG, "Could not get application restrictions for package " + packageName);
9577e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        }
9587e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        return null;
9597e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    }
960df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
961df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
962df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
963df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
9647e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
965df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
9667e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
967df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
968df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier());
969df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
970df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        return null;
971df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
972df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
973df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
974df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
975df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
9767e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public void setApplicationRestrictions(String packageName, Bundle restrictions,
977df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            UserHandle user) {
978df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
9797e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
980df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
981df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier());
982df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
983df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
984655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
985655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
986d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * Sets a new challenge PIN for restrictions. This is only for use by pre-installed
987d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * apps and requires the MANAGE_USERS permission.
988d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @param newPin the PIN to use for challenge dialogs.
989d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @return Returns true if the challenge PIN was set successfully.
990655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
991d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public boolean setRestrictionsChallenge(String newPin) {
992655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        try {
993d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani            return mService.setRestrictionsChallenge(newPin);
994655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        } catch (RemoteException re) {
995655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani            Log.w(TAG, "Could not change restrictions pin");
996655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        }
997655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return false;
998655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
999655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
1000655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
1001655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * @hide
1002655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * @param pin The PIN to verify, or null to get the number of milliseconds to wait for before
1003655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * allowing the user to enter the PIN.
1004655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * @return Returns a positive number (including zero) for how many milliseconds before
1005655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * you can accept another PIN, when the input is null or the input doesn't match the saved PIN.
1006655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * Returns {@link #PIN_VERIFICATION_SUCCESS} if the input matches the saved PIN. Returns
1007655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * {@link #PIN_VERIFICATION_FAILED_NOT_SET} if there is no PIN set.
1008655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
1009d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public int checkRestrictionsChallenge(String pin) {
1010655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        try {
1011d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani            return mService.checkRestrictionsChallenge(pin);
1012655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        } catch (RemoteException re) {
1013655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani            Log.w(TAG, "Could not check restrictions pin");
1014655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        }
1015655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return PIN_VERIFICATION_FAILED_INCORRECT;
1016655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
1017655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
1018655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
1019d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @hide
1020655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * Checks whether the user has restrictions that are PIN-protected. An application that
1021655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * participates in restrictions can check if the owner has requested a PIN challenge for
1022655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * any restricted operations. If there is a PIN in effect, the application should launch
1023d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * the PIN challenge activity {@link android.content.Intent#ACTION_RESTRICTIONS_CHALLENGE}.
1024d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @see android.content.Intent#ACTION_RESTRICTIONS_CHALLENGE
1025655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * @return whether a restrictions PIN is in effect.
1026655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
1027d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public boolean hasRestrictionsChallenge() {
1028655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        try {
1029d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani            return mService.hasRestrictionsChallenge();
1030655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        } catch (RemoteException re) {
1031655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani            Log.w(TAG, "Could not change restrictions pin");
1032655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        }
1033655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return false;
1034655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
10351a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani
10361a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    /** @hide */
10371a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    public void removeRestrictions() {
10381a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        try {
10391a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani            mService.removeRestrictions();
10401a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        } catch (RemoteException re) {
10411a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani            Log.w(TAG, "Could not change restrictions pin");
10421a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        }
10431a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    }
1044e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani
1045e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    /**
1046e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * @hide
1047e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * Set restrictions that should apply to any future guest user that's created.
1048e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     */
1049e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    public void setDefaultGuestRestrictions(Bundle restrictions) {
1050e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        try {
1051e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            mService.setDefaultGuestRestrictions(restrictions);
1052e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        } catch (RemoteException re) {
1053e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            Log.w(TAG, "Could not set guest restrictions");
1054e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        }
1055e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    }
1056e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani
1057e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    /**
1058e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * @hide
1059e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * Gets the default guest restrictions.
1060e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     */
1061e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    public Bundle getDefaultGuestRestrictions() {
1062e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        try {
1063e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            return mService.getDefaultGuestRestrictions();
1064e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        } catch (RemoteException re) {
1065e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            Log.w(TAG, "Could not set guest restrictions");
1066e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        }
1067e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        return new Bundle();
1068e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    }
1069258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani}
1070