UserManager.java revision c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8
1258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/*
2258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Copyright (C) 2012 The Android Open Source Project
3258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani *
4258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Licensed under the Apache License, Version 2.0 (the "License");
5258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * you may not use this file except in compliance with the License.
6258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * You may obtain a copy of the License at
7258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani *
8258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani *      http://www.apache.org/licenses/LICENSE-2.0
9258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani *
10258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Unless required by applicable law or agreed to in writing, software
11258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * distributed under the License is distributed on an "AS IS" BASIS,
12258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * See the License for the specific language governing permissions and
14258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * limitations under the License.
15258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */
16258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipackage android.os;
17258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
180e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasaniimport android.annotation.SystemApi;
19409297da182267465adbc21cfb75a23e8d678117Dianne Hackbornimport android.app.ActivityManager;
20a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackbornimport android.app.ActivityManagerNative;
21258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.Context;
22988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powellimport android.content.pm.PackageManager;
23258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.pm.UserInfo;
2427bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkeyimport android.content.res.Resources;
256794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport android.graphics.Bitmap;
264f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.Rect;
274f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.drawable.Drawable;
281e9c21871e81642669079cd290ef47818a3165bdAmith Yamasaniimport android.provider.Settings;
29258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.util.Log;
301c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monkimport android.view.WindowManager.LayoutParams;
31258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
326794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport com.android.internal.R;
336794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
344f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport java.util.ArrayList;
35258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport java.util.List;
36258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
37258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/**
38258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Manages users and user details on a multi-user system.
39258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */
40258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipublic class UserManager {
41258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
42258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private static String TAG = "UserManager";
43258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private final IUserManager mService;
44258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private final Context mContext;
45258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
46e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
4726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from adding and removing accounts.
4871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
4926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
5026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
5126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
52e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
53e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
54e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
5571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
56e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
57e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
5826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from changing Wi-Fi
592cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * access points. The default value is <code>false</code>.
6026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
6126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
6226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
63e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
64e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
65e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
6671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi";
67e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
68e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
6926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from installing applications.
7071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
7126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
7226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
7326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
74e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
75e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
76e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
7771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_INSTALL_APPS = "no_install_apps";
78e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
79e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
8026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from uninstalling applications.
8171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
8226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
8326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
8426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
85e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
86e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
87e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
8871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
89e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
9071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
9126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from toggling location sharing.
9271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
9326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
9426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
9526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
966794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     * @see #setUserRestrictions(Bundle)
976794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     * @see #getUserRestrictions()
986794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
9971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_SHARE_LOCATION = "no_share_location";
1006794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
101a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
10226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from enabling the
103a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * "Unknown Sources" setting, that allows installation of apps from unknown sources.
104a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * The default value is <code>false</code>.
10526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
10626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
10726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
108a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
109a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
110a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
111a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
112a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
113a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
11426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring bluetooth.
115a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * The default value is <code>false</code>.
11626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
11726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
11826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
119a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
120a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
121a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
122a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
123a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
124a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
12526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from transferring files over
126c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * USB. This can only be set by device owners and profile owners on the primary user.
127c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
12826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
12926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
13026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
131a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
132a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
133a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
134a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
135a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
136b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    /**
13726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring user
138b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * credentials. The default value is <code>false</code>.
13926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
14026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
14126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
142b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #setUserRestrictions(Bundle)
143b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
144b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
145b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
146b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
147b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    /**
14826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from removing itself and other
1492cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * users. The default value is <code>false</code>.
15026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
15126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
15226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
153b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #setUserRestrictions(Bundle)
154b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
155b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
156b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_REMOVE_USER = "no_remove_user";
157b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
158d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
15926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from enabling or
160d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * accessing debugging features. The default value is <code>false</code>.
16126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
16226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
16326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
164d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
165d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
166d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
167d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
168d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
169d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
17026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring VPN.
171d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * The default value is <code>false</code>.
17226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
17326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
17426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
175d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
176d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
177d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
178d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_VPN = "no_config_vpn";
179d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
180d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
18126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring Tethering
182c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * & portable hotspots. This can only be set by device owners and profile owners on the
183c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * primary user. The default value is <code>false</code>.
18426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
18526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
18626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
187d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
188d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
189d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
190d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering";
191d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
192d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
19326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from factory resetting
194c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * from Settings. This can only be set by device owners and profile owners on the primary user.
195c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
19626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
19726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
19826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
199d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
200d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
201d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
202d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_FACTORY_RESET = "no_factory_reset";
203d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
204d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
20526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from adding new users and
206c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * profiles. This can only be set by device owners and profile owners on the primary user.
207c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
20826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
20926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
21026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
211d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
212d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
213d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
214d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_ADD_USER = "no_add_user";
215d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
216d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
21726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from disabling application
218d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * verification. The default value is <code>false</code>.
21926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
22026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
22126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
222d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
223d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
224d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
225d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps";
226d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
227d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
22826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring cell
229c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * broadcasts. This can only be set by device owners and profile owners on the primary user.
230c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
23126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
23226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
23326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
234d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
235d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
236d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
237d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts";
238d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
239d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
24026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring mobile
241c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * networks. This can only be set by device owners and profile owners on the primary user.
242c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
24326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
24426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
24526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
246d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
247d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
248d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
249d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks";
250d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
251d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
25226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from modifying
253c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * applications in Settings or launchers. The following actions will not be allowed when this
254c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * restriction is enabled:
255c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>uninstalling apps</li>
256c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>disabling apps</li>
257c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app caches</li>
258c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app data</li>
259c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>force stopping apps</li>
260c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app defaults</li>
261c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <p>
262c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * The default value is <code>false</code>.
26326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
26426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
26526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
266d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
267d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
268d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
26936fbc8d6453da438a8ab83352ff1bcfcba5f25b5Julia Reynolds    public static final String DISALLOW_APPS_CONTROL = "no_control_apps";
270d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
271394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
27226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from mounting
273c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * physical external media. This can only be set by device owners and profile owners on the
274c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * primary user. The default value is <code>false</code>.
27526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
27626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
27726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
278394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
279394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
280394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
281394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
282394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
283394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
28426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from adjusting microphone
285c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * volume. If set, the microphone will be muted. This can only be set by device owners
286c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * and profile owners on the primary user. The default value is <code>false</code>.
28726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
28826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
28926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
290394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
291394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
292394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
293394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
294394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
295394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
29626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from adjusting the master
297c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * volume. If set, the master volume will be muted. This can only be set by device owners
298c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * and profile owners on the primary user. The default value is <code>false</code>.
29926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
30026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
30126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
302394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
303394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
304394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
305394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume";
306394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
3079f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani    /**
30826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that the user is not allowed to make outgoing
309390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * phone calls. Emergency calls are still permitted.
310390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * The default value is <code>false</code>.
31126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
31226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
31326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
314390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * @see #setUserRestrictions(Bundle)
315390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * @see #getUserRestrictions()
316390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     */
317390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls";
318390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani
319390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    /**
32026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that the user is not allowed to send or receive
321c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * SMS messages. The default value is <code>false</code>.
32226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
32326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
32426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
3259f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * @see #setUserRestrictions(Bundle)
3269f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * @see #getUserRestrictions()
3279f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     */
328390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    public static final String DISALLOW_SMS = "no_sms";
3299f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani
3301c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk    /**
33126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that windows besides app windows should not be
3321c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * created. This will block the creation of the following types of windows.
3331c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_TOAST}</li>
3341c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_PHONE}</li>
3351c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li>
3361c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li>
3371c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li>
3381c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li>
3391c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     *
340c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * <p>This can only be set by device owners and profile owners on the primary user.
341c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
34226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
34326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
34426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
3451c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * @see #setUserRestrictions(Bundle)
3461c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * @see #getUserRestrictions()
3471c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     */
3481c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk    public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows";
3491c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk
350f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot    /**
35126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if what is copied in the clipboard of this profile can
352f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be
353f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * pasted in this profile.
354f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * The default value is <code>false</code>.
35526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
35626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
35726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
358f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * @see #setUserRestrictions(Bundle)
359f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * @see #getUserRestrictions()
360f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     */
361f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot    public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste";
362f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot
36326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani    /**
36426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if the user is not allowed to use NFC to beam out data from apps.
36526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * The default value is <code>false</code>.
36626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
36726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
36826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
36926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * @see #setUserRestrictions(Bundle)
37026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * @see #getUserRestrictions()
37126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     */
37226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani    public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam";
37326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani
374655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
375655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
376655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
377655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2;
378655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
379655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_SUCCESS = -1;
380655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
38127db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    private static UserManager sInstance = null;
38227db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani
3837e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /** @hide */
38427db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    public synchronized static UserManager get(Context context) {
38527db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        if (sInstance == null) {
38627db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani            sInstance = (UserManager) context.getSystemService(Context.USER_SERVICE);
38727db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        }
38827db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        return sInstance;
38927db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    }
390a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
391258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /** @hide */
392258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserManager(Context context, IUserManager service) {
393258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        mService = service;
394258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        mContext = context;
395258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
396258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
397258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
398258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns whether the system supports multiple users.
3991a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @return true if multiple users can be created by user, false if it is a single user device.
400e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @hide
401258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
4024673e7ea8d1f869910a9c0f9c211d4d27ad50b41Jeff Sharkey    public static boolean supportsMultipleUsers() {
4031a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        return getMaxSupportedUsers() > 1
4041a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                && SystemProperties.getBoolean("fw.show_multiuserui",
4051a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));
406258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
407258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
4086794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    /**
409be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns the user handle for the user that the calling process is running on.
410be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     *
411258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the user handle of the user making this call.
412258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
4136794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
414258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public int getUserHandle() {
41579af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn        return UserHandle.myUserId();
416258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
417258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
418258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
4198832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * Returns the user name of the user making this call.  This call is only
4208832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * available to applications on the system image; it requires the
4218832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * MANAGE_USERS permission.
422258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the user name
423258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
424258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public String getUserName() {
425258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
426258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(getUserHandle()).name;
427258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
428258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user name", re);
429258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return "";
430258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
431258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
432258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
433e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill   /**
434e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * Used to determine whether the user making this call is subject to
435e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * teleportations.
436a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @return whether the user making this call is a goat
437e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     */
438e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    public boolean isUserAGoat() {
439988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell        return mContext.getPackageManager()
440988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell                .isPackageAvailable("com.coffeestainstudios.goatsimulator");
441e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    }
442df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
443df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
444e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * Used to check if the user making this call is linked to another user. Linked users may have
44546bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani     * a reduced number of available apps, app restrictions and account restrictions.
446e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * @return whether the user making this call is a linked user
4472555dafce87e60fae28d71913730abf73e40fcd7Amith Yamasani     * @hide
448df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
449e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani    public boolean isLinkedUser() {
450df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
45171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani            return mService.isRestricted();
452df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
45346bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani            Log.w(TAG, "Could not check if user is limited ", re);
454df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            return false;
455df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
456df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
457df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
458258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
4591e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * Checks if the calling app is running as a guest user.
4601e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @return whether the caller is a guest user.
4611e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @hide
4621e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     */
4631e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    public boolean isGuestUser() {
4641e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        UserInfo user = getUserInfo(UserHandle.myUserId());
4651e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        return user != null ? user.isGuest() : false;
4661e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    }
4671e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani
4681e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    /**
4690e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * Checks if the calling app is running in a managed profile.
4700e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
4710e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     *
4720e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * @return whether the caller is in a managed profile.
4730e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * @hide
4740e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     */
4750e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    @SystemApi
4760e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    public boolean isManagedProfile() {
4770e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani        UserInfo user = getUserInfo(UserHandle.myUserId());
4780e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani        return user != null ? user.isManagedProfile() : false;
4790e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    }
4800e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani
4810e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    /**
482a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running.  This means that
483a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * the user is in the "started" state, not "stopped" -- it is currently
484a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * allowed to run code through scheduled alarms, receiving broadcasts,
485a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * etc.  A started user may be either the current foreground user or a
486a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * background user; the result here does not distinguish between the two.
487a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
488a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
489a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunning(UserHandle user) {
490a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
491a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return ActivityManagerNative.getDefault().isUserRunning(
492a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn                    user.getIdentifier(), false);
493a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        } catch (RemoteException e) {
494a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return false;
495a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
496a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
497a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
498a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    /**
499a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running <em>or</em> stopping.
500a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * This is like {@link #isUserRunning(UserHandle)}, but will also return
501a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * true if the user had been running but is in the process of being stopped
502a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * (but is not yet fully stopped, and still running some code).
503a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
504a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
505a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunningOrStopping(UserHandle user) {
506a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
507a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return ActivityManagerNative.getDefault().isUserRunning(
508a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn                    user.getIdentifier(), true);
509a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        } catch (RemoteException e) {
510a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return false;
511a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
512a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
513a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
514a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    /**
515258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the UserInfo object describing a specific user.
5161952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
517258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user handle of the user whose information is being requested.
518258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for a specific user.
519258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
520b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
521258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserInfo getUserInfo(int userHandle) {
522258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
523258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(userHandle);
524258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
525258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user info", re);
526258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
527258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
528258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
529258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
53071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
53171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on this user.
53271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
53371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
534e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions() {
535e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        return getUserRestrictions(Process.myUserHandle());
536e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
537e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
53871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
53971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
54071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
54171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
54271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
543e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions(UserHandle userHandle) {
544e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        try {
545e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            return mService.getUserRestrictions(userHandle.getIdentifier());
546e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        } catch (RemoteException re) {
547e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            Log.w(TAG, "Could not get user restrictions", re);
548e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            return Bundle.EMPTY;
549e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        }
550e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
551e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
55271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
55371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets all the user-wide restrictions for this user.
554be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
55571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param restrictions the Bundle containing all the restrictions.
5563d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
5573d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
5583d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
5593d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
56071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
5613d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
562e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions) {
563e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        setUserRestrictions(restrictions, Process.myUserHandle());
564e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
565e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
56671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
56771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets all the user-wide restrictions for the specified user.
568be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
56971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param restrictions the Bundle containing all the restrictions.
57071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the UserHandle of the user for whom to set the restrictions.
5713d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
5723d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
5733d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
5743d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
57571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
5763d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
577e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
578e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        try {
579e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            mService.setUserRestrictions(restrictions, userHandle.getIdentifier());
580e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        } catch (RemoteException re) {
581e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            Log.w(TAG, "Could not set user restrictions", re);
582e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        }
583e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
584e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
58571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
58671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction.
587be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
58871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
58971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
5903d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
5913d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
5923d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
5933d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
59471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
5953d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
59671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public void setUserRestriction(String key, boolean value) {
59771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        Bundle bundle = getUserRestrictions();
59871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        bundle.putBoolean(key, value);
59971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        setUserRestrictions(bundle);
60071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    }
60171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani
60271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
60371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @hide
60471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction on a specific user.
605be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
60671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
60771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
60871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the user whose restriction is to be changed.
6093d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
6103d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
6113d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
6123d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
61371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
6143d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
6156794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
6166794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall        Bundle bundle = getUserRestrictions(userHandle);
6176794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall        bundle.putBoolean(key, value);
6186794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall        setUserRestrictions(bundle, userHandle);
6196794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    }
6206794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
621258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
622a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Returns whether the current user has been disallowed from performing certain actions
623a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * or setting certain settings.
6242b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     *
6252b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     * @param restrictionKey The string key representing the restriction.
6262b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     * @return {@code true} if the current user has the given restriction, {@code false} otherwise.
627a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
628a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public boolean hasUserRestriction(String restrictionKey) {
629b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie        return hasUserRestriction(restrictionKey, Process.myUserHandle());
630b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    }
631b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie
632b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    /**
633b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @hide
634b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * Returns whether the given user has been disallowed from performing certain actions
635b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * or setting certain settings.
636b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param restrictionKey the string key representing the restriction
637b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
638b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     */
639b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
6408cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        try {
6418cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani            return mService.hasUserRestriction(restrictionKey,
6428cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani                    userHandle.getIdentifier());
6438cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        } catch (RemoteException re) {
6448cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani            Log.w(TAG, "Could not check user restrictions", re);
6458cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani            return false;
6468cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        }
647a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    }
648a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
649a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
65033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the serial number for a user.  This is a device-unique
651b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * number assigned to that user; if the user is deleted and then a new
652b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * user created, the new users will not be given the same serial number.
65333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param user The user whose serial number is to be retrieved.
654b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * @return The serial number of the given user; returns -1 if the
655b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * given UserHandle does not exist.
65633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getUserForSerialNumber(long)
65733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
65833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public long getSerialNumberForUser(UserHandle user) {
65933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return getUserSerialNumber(user.getIdentifier());
66033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
66133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
66233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
66333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the user associated with a serial number previously
66433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * returned by {@link #getSerialNumberForUser(UserHandle)}.
66533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param serialNumber The serial number of the user that is being
66633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * retrieved.
66733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @return Return the user associated with the serial number, or null
66833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * if there is not one.
66933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getSerialNumberForUser(UserHandle)
67033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
67133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public UserHandle getUserForSerialNumber(long serialNumber) {
67233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        int ident = getUserHandle((int)serialNumber);
67333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return ident >= 0 ? new UserHandle(ident) : null;
67433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
67533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
67633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
677258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Creates a user with the specified name and options.
6781952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
679258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
680258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the user's name
681258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param flags flags that identify the type of user and other properties.
682258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @see UserInfo
683258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
684258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for the created user, or null if the user could not be created.
685258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
686258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
687258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserInfo createUser(String name, int flags) {
688258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
689258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.createUser(name, flags);
690258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
691258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not create a user", re);
692258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
693258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
694258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
695258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
696258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
6971e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * Creates a guest user and configures it.
6981e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @param context an application context
6991e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @param name the name to set for the user
7001e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @hide
7011e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     */
7021e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    public UserInfo createGuest(Context context, String name) {
7031e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        UserInfo guest = createUser(name, UserInfo.FLAG_GUEST);
7041e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        if (guest != null) {
7051e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani            Settings.Secure.putStringForUser(context.getContentResolver(),
7061e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani                    Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
707bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani            try {
7088616af1a4dd1877996fbd5bb0179659f4f123573Amith Yamasani                Bundle guestRestrictions = mService.getDefaultGuestRestrictions();
7098616af1a4dd1877996fbd5bb0179659f4f123573Amith Yamasani                guestRestrictions.putBoolean(DISALLOW_SMS, true);
71029ce85bab94a2d0dc98d9075ae86c8a282367117Amith Yamasani                guestRestrictions.putBoolean(DISALLOW_INSTALL_UNKNOWN_SOURCES, true);
7118616af1a4dd1877996fbd5bb0179659f4f123573Amith Yamasani                mService.setUserRestrictions(guestRestrictions, guest.id);
712bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani            } catch (RemoteException re) {
713bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani                Log.w(TAG, "Could not update guest restrictions");
714bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani            }
7151e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        }
7161e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        return guest;
7171e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    }
7181e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani
7191e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    /**
7202a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Creates a user with the specified name and options as a profile of another user.
721a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
722a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     *
723a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @param name the user's name
724a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @param flags flags that identify the type of user and other properties.
725a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @see UserInfo
7262a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @param userHandle new user will be a profile of this use.
727a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     *
728a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @return the UserInfo object for the created user, or null if the user could not be created.
729a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @hide
730a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     */
7312a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy    public UserInfo createProfileForUser(String name, int flags, int userHandle) {
732a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        try {
7332a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy            return mService.createProfileForUser(name, flags, userHandle);
734a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        } catch (RemoteException re) {
735a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            Log.w(TAG, "Could not create a user", re);
736a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            return null;
737a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        }
738a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    }
739a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy
740a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    /**
7411df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @hide
7421df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * Marks the guest user for deletion to allow a new guest to be created before deleting
7431df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * the current user who is a guest.
7441df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @param userHandle
7451df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @return
7461df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     */
7471df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    public boolean markGuestForDeletion(int userHandle) {
7481df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        try {
7491df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani            return mService.markGuestForDeletion(userHandle);
7501df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        } catch (RemoteException re) {
7511df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani            Log.w(TAG, "Could not mark guest for deletion", re);
7521df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani            return false;
7531df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        }
7541df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    }
7551df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani
7561df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    /**
757df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Sets the user as enabled, if such an user exists.
758df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
759df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Note that the default is true, it's only that managed profiles might not be enabled.
760df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     *
761df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * @param userHandle the id of the profile to enable
762df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * @hide
763df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     */
764df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    public void setUserEnabled(int userHandle) {
765df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        try {
766df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina            mService.setUserEnabled(userHandle);
767df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        } catch (RemoteException e) {
768df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina            Log.w(TAG, "Could not enable the profile", e);
769df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        }
770df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    }
771df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina
772df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    /**
773b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * Return the number of users currently created on the device.
774b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
775b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    public int getUserCount() {
776b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        List<UserInfo> users = getUsers();
777b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        return users != null ? users.size() : 1;
778b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    }
779b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn
780b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    /**
781258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns information for all users on this device.
7821952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
783258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the list of users that were created.
784258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
785258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
786258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public List<UserInfo> getUsers() {
787258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
788920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(false);
789920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        } catch (RemoteException re) {
790920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            Log.w(TAG, "Could not get user list", re);
791920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return null;
792920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        }
793920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    }
794920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani
795920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    /**
79695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS
79795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * permission.
79895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     *
79995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * @return true if more users can be added, false if limit has been reached.
80095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * @hide
80195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     */
80295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    public boolean canAddMoreUsers() {
80395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        final List<UserInfo> users = getUsers(true);
80495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        final int totalUserCount = users.size();
80595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        int aliveUserCount = 0;
80695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        for (int i = 0; i < totalUserCount; i++) {
80795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            UserInfo user = users.get(i);
80895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            if (!user.isGuest()) {
80995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani                aliveUserCount++;
81095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            }
81195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        }
81295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        return aliveUserCount < getMaxSupportedUsers();
81395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    }
81495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani
81595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    /**
8162a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Returns list of the profiles of userHandle including
8172a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * userHandle itself.
8184f7e2e334e4ca5f1a67baf4bdd40cd080b954161Amith Yamasani     * Note that this returns both enabled and not enabled profiles. See
819385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina     * {@link #getUserProfiles()} if you need only the enabled ones.
8204f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *
8212a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
8222a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @param userHandle profiles of this user will be returned.
8232a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @return the list of profiles.
8242a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @hide
8252a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     */
8262a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy    public List<UserInfo> getProfiles(int userHandle) {
827a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        try {
828385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            return mService.getProfiles(userHandle, false /* enabledOnly */);
829a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        } catch (RemoteException re) {
830a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            Log.w(TAG, "Could not get user list", re);
831a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            return null;
832a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        }
833a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    }
834a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy
835a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    /**
836be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns a list of UserHandles for profiles associated with the user that the calling process
837be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * is running on, including the user itself.
8384f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *
8394f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * @return A non-empty list of UserHandles associated with the calling user.
8404f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     */
8414f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    public List<UserHandle> getUserProfiles() {
8424f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        ArrayList<UserHandle> profiles = new ArrayList<UserHandle>();
843385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        List<UserInfo> users = new ArrayList<UserInfo>();
844385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        try {
845f2e7b3f56ae0ea9f49b5c50413b9be71d5249d6dAlexandra Gherghina            users = mService.getProfiles(UserHandle.myUserId(), true /* enabledOnly */);
846385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        } catch (RemoteException re) {
847385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            Log.w(TAG, "Could not get user list", re);
848385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            return null;
849385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        }
8504f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        for (UserInfo info : users) {
8514f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            UserHandle userHandle = new UserHandle(info.id);
8524f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            profiles.add(userHandle);
8534f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        }
8544f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        return profiles;
8554f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
8564f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
8577dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani    /**
858be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns the parent of the profile which this method is called from
859be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * or null if called from a user that is not a profile.
860be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     *
861be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * @hide
862be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     */
863be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    public UserInfo getProfileParent(int userHandle) {
864be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        try {
865be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            return mService.getProfileParent(userHandle);
866be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        } catch (RemoteException re) {
867be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            Log.w(TAG, "Could not get profile parent", re);
868be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            return null;
869be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        }
870be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    }
871be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel
872be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    /**
8737dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * If the target user is a managed profile of the calling user or the caller
8747dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * is itself a managed profile, then this returns a badged copy of the given
875c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * icon to be able to distinguish it from the original icon. For badging an
876c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * arbitrary drawable use {@link #getBadgedDrawableForUser(
877c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
878c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * <p>
879c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the original drawable is a BitmapDrawable and the backing bitmap is
880c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
881c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is performed in place and the original drawable is returned.
882c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * </p>
883c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *
884c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param icon The icon to badge.
885c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param user The target user.
886c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @return A drawable that combines the original icon and a badge as
887c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         determined by the system.
888c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
889c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     */
890c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) {
891c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedIcon(icon, user);
892c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    }
893c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav
894c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    /**
895c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the target user is a managed profile of the calling user or the caller
896c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is itself a managed profile, then this returns a badged copy of the given
897c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * drawable allowing the user to distinguish it from the original drawable.
898c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * The caller can specify the location in the bounds of the drawable to be
899c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * badged where the badge should be applied as well as the density of the
900c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * badge to be used.
901c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * <p>
902c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the original drawable is a BitmapDrawable and the backing bitmap is
903c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
904c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is performed in place and the original drawable is returned.
905c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * </p>
906c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *
907c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgedDrawable The drawable to badge.
908c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param user The target user.
909c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgeLocation Where in the bounds of the badged drawable to place
910c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         the badge. If not provided, the badge is applied on top of the entire
911c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         drawable being badged.
912c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgeDensity The optional desired density for the badge as per
913c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         {@link android.util.DisplayMetrics#densityDpi}. If not provided,
914c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         the density of the display is used.
915c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @return A drawable that combines the original drawable and a badge as
916c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         determined by the system.
917c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
918c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     */
919c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user,
920c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            Rect badgeLocation, int badgeDensity) {
921c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user,
922c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav                badgeLocation, badgeDensity);
9234f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
9244f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
925701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    /**
926701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * If the target user is a managed profile of the calling user or the caller
927f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * is itself a managed profile, then this returns a copy of the label with
928f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * badging for accessibility services like talkback. E.g. passing in "Email"
929f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * and it might return "Work Email" for Email in the work profile.
930f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     *
931f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @param label The label to change.
932f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @param user The target user.
933f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @return A label that combines the original label and a badge as
934f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     *         determined by the system.
935c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
936f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     */
937237aecd18d0edf56c038761f570758c310c9e6dfKenny Guy    public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) {
938c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedLabel(label, user);
9394f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
9404f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
9414f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    /**
9424f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * Returns information for all users on this device. Requires
9434f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * {@link android.Manifest.permission#MANAGE_USERS} permission.
944394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     *
9454f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * @param excludeDying specify if the list should exclude users being
9464f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *            removed.
947920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @return the list of users that were created.
948920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @hide
949920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     */
950920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    public List<UserInfo> getUsers(boolean excludeDying) {
951920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        try {
952920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(excludeDying);
953258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
954258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user list", re);
955258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
956258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
957258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
958258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
959258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
960258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Removes a user and all associated data.
9611952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
962258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the integer handle of the user, where 0 is the primary user.
963258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
964258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
965258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public boolean removeUser(int userHandle) {
966258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
967258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.removeUser(userHandle);
968258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
969258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not remove user ", re);
970258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return false;
971258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
972258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
973258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
974258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
975258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Updates the user's name.
9761952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
977258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
978258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user's integer handle
979258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the new name for the user
980258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
981258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
982258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public void setUserName(int userHandle, String name) {
983258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
984258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            mService.setUserName(userHandle, name);
985258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
986258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not set the user name ", re);
987258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
988258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
989258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
990258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
991e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * Sets the user's photo.
992258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user for whom to change the photo.
993e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @param icon the bitmap to set as the photo.
994258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
995258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
996e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani    public void setUserIcon(int userHandle, Bitmap icon) {
997258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
998e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani            mService.setUserIcon(userHandle, icon);
999258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1000258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not set the user icon ", re);
1001258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1002258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1003258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1004258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
10053b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * Returns a file descriptor for the user's photo. PNG data can be read from this file.
10063b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @param userHandle the user whose photo we want to read.
1007e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
100864d4dca63f65e4c7d4a829c85ff6670bdd34e2ebAlexandra Gherghina     * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
10093b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @hide
10103b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     */
1011e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani    public Bitmap getUserIcon(int userHandle) {
10123b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        try {
10133b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani            return mService.getUserIcon(userHandle);
10143b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        } catch (RemoteException re) {
1015e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani            Log.w(TAG, "Could not get the user icon ", re);
10163b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani            return null;
10173b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        }
10183b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    }
10193b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani
10203b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    /**
1021258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the maximum number of users that can be created on this device. A return value
1022258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * of 1 means that it is a single user device.
1023258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1024a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @return a value greater than or equal to 1
1025258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
102627bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey    public static int getMaxSupportedUsers() {
1027ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        // Don't allow multiple users on certain builds
1028ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        if (android.os.Build.ID.startsWith("JVP")) return 1;
1029409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn        // Svelte devices don't get multi-user.
1030409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn        if (ActivityManager.isLowRamDeviceStatic()) return 1;
103127bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey        return SystemProperties.getInt("fw.max_users",
103227bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey                Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
1033258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
10342a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
10352a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
10361a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * Returns true if the user switcher should be shown, this will be if there
10371a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * are multiple users that aren't managed profiles.
10381a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @hide
10391a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @return true if user switcher should be shown.
10401a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     */
10411a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    public boolean isUserSwitcherEnabled() {
10421a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        List<UserInfo> users = getUsers(true);
10431a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        if (users == null) {
10441a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy           return false;
10451a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        }
10461a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        int switchableUserCount = 0;
10471a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        for (UserInfo user : users) {
10481a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy            if (user.supportsSwitchTo()) {
10491a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                ++switchableUserCount;
10501a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy            }
10511a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        }
1052a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani        final boolean guestEnabled = Settings.Global.getInt(mContext.getContentResolver(),
1053a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani                Settings.Global.GUEST_USER_ENABLED, 0) == 1;
1054a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani        return switchableUserCount > 1 || guestEnabled;
10551a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    }
10561a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy
10571a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    /**
10582a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a serial number on this device for a given userHandle. User handles can be recycled
10592a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * when deleting and creating users, but serial numbers are not reused until the device is wiped.
10602a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userHandle
10612a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return a serial number associated with that user, or -1 if the userHandle is not valid.
10622a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
10632a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
10642a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    public int getUserSerialNumber(int userHandle) {
10652a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
10662a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserSerialNumber(userHandle);
10672a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
10682a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            Log.w(TAG, "Could not get serial number for user " + userHandle);
10692a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
10702a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        return -1;
10712a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
10722a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
10732a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
10742a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a userHandle on this device for a given user serial number. User handles can be
10752a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * recycled when deleting and creating users, but serial numbers are not reused until the device
10762a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is wiped.
10772a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userSerialNumber
10782a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return the userHandle associated with that user serial number, or -1 if the serial number
10792a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is not valid.
10802a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
10812a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
10822a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    public int getUserHandle(int userSerialNumber) {
10832a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
10842a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserHandle(userSerialNumber);
10852a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
10862a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            Log.w(TAG, "Could not get userHandle for user " + userSerialNumber);
10872a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
10882a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        return -1;
10892a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
10906794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
10917e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /**
10927e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * Returns a Bundle containing any saved application restrictions for this user, for the
10937e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * given package name. Only an application with this package name can call this method.
10947e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * @param packageName the package name of the calling application
10957e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * @return a Bundle with the restrictions as key/value pairs, or null if there are no
10967e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * saved restrictions. The values can be of type Boolean, String or String[], depending
10977e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * on the restriction type, as defined by the application.
10987e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     */
10997e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName) {
11007e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        try {
11017e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictions(packageName);
11027e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        } catch (RemoteException re) {
11037e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            Log.w(TAG, "Could not get application restrictions for package " + packageName);
11047e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        }
11057e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        return null;
11067e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    }
1107df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
1108df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
1109df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
1110df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
11117e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
1112df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
11137e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
1114df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
1115df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier());
1116df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
1117df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        return null;
1118df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
1119df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
1120df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
1121df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
1122df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
11237e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public void setApplicationRestrictions(String packageName, Bundle restrictions,
1124df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            UserHandle user) {
1125df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
11267e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
1127df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
1128df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier());
1129df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
1130df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
1131655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
1132655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
1133d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * Sets a new challenge PIN for restrictions. This is only for use by pre-installed
1134d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * apps and requires the MANAGE_USERS permission.
1135d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @param newPin the PIN to use for challenge dialogs.
1136d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @return Returns true if the challenge PIN was set successfully.
1137655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
1138d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public boolean setRestrictionsChallenge(String newPin) {
1139655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        try {
1140d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani            return mService.setRestrictionsChallenge(newPin);
1141655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        } catch (RemoteException re) {
1142655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani            Log.w(TAG, "Could not change restrictions pin");
1143655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        }
1144655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return false;
1145655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
1146655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
1147655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
1148655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * @hide
1149655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * @param pin The PIN to verify, or null to get the number of milliseconds to wait for before
1150655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * allowing the user to enter the PIN.
1151655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * @return Returns a positive number (including zero) for how many milliseconds before
1152655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * you can accept another PIN, when the input is null or the input doesn't match the saved PIN.
1153655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * Returns {@link #PIN_VERIFICATION_SUCCESS} if the input matches the saved PIN. Returns
1154655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * {@link #PIN_VERIFICATION_FAILED_NOT_SET} if there is no PIN set.
1155655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
1156d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public int checkRestrictionsChallenge(String pin) {
1157655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        try {
1158d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani            return mService.checkRestrictionsChallenge(pin);
1159655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        } catch (RemoteException re) {
1160655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani            Log.w(TAG, "Could not check restrictions pin");
1161655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        }
1162655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return PIN_VERIFICATION_FAILED_INCORRECT;
1163655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
1164655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
1165655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
1166d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @hide
1167655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * Checks whether the user has restrictions that are PIN-protected. An application that
1168655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * participates in restrictions can check if the owner has requested a PIN challenge for
1169655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * any restricted operations. If there is a PIN in effect, the application should launch
1170d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * the PIN challenge activity {@link android.content.Intent#ACTION_RESTRICTIONS_CHALLENGE}.
1171d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @see android.content.Intent#ACTION_RESTRICTIONS_CHALLENGE
1172655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * @return whether a restrictions PIN is in effect.
1173655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
1174d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public boolean hasRestrictionsChallenge() {
1175655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        try {
1176d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani            return mService.hasRestrictionsChallenge();
1177655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        } catch (RemoteException re) {
1178655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani            Log.w(TAG, "Could not change restrictions pin");
1179655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        }
1180655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return false;
1181655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
11821a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani
11831a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    /** @hide */
11841a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    public void removeRestrictions() {
11851a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        try {
11861a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani            mService.removeRestrictions();
11871a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        } catch (RemoteException re) {
11881a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani            Log.w(TAG, "Could not change restrictions pin");
11891a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        }
11901a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    }
1191e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani
1192e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    /**
1193e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * @hide
1194e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * Set restrictions that should apply to any future guest user that's created.
1195e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     */
1196e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    public void setDefaultGuestRestrictions(Bundle restrictions) {
1197e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        try {
1198e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            mService.setDefaultGuestRestrictions(restrictions);
1199e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        } catch (RemoteException re) {
1200e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            Log.w(TAG, "Could not set guest restrictions");
1201e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        }
1202e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    }
1203e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani
1204e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    /**
1205e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * @hide
1206e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * Gets the default guest restrictions.
1207e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     */
1208e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    public Bundle getDefaultGuestRestrictions() {
1209e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        try {
1210e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            return mService.getDefaultGuestRestrictions();
1211e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        } catch (RemoteException re) {
1212e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            Log.w(TAG, "Could not set guest restrictions");
1213e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        }
1214e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        return new Bundle();
1215e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    }
1216258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani}
1217