UserManager.java revision c4dd021322d38ea32ac49930e904b6d08ce6490c
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
1802cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolovimport android.accounts.AccountManager;
197cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chenimport android.annotation.Nullable;
200e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasaniimport android.annotation.SystemApi;
21409297da182267465adbc21cfb75a23e8d678117Dianne Hackbornimport android.app.ActivityManager;
22a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackbornimport android.app.ActivityManagerNative;
23cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolovimport android.app.admin.DevicePolicyManager;
24068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onukiimport android.content.ComponentName;
25258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.Context;
26258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.pm.UserInfo;
2727bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkeyimport android.content.res.Resources;
286794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport android.graphics.Bitmap;
291bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roosimport android.graphics.BitmapFactory;
304f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.Rect;
314f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.drawable.Drawable;
321e9c21871e81642669079cd290ef47818a3165bdAmith Yamasaniimport android.provider.Settings;
33258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.util.Log;
341c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monkimport android.view.WindowManager.LayoutParams;
35258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
366794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport com.android.internal.R;
376794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
381bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roosimport java.io.IOException;
394f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport java.util.ArrayList;
40258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport java.util.List;
41258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
42258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/**
43258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Manages users and user details on a multi-user system.
44258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */
45258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipublic class UserManager {
46258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
47258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private static String TAG = "UserManager";
48258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private final IUserManager mService;
49258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private final Context mContext;
50258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
51e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
5253019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov     * Specifies if a user is disallowed from adding and removing accounts, unless they are
5353019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov     * {@link android.accounts.AccountManager#addAccountExplicitly programmatically} added by
5453019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov     * Authenticator.
5571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
5626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
5726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
5826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
59068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
60068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
61e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
62e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
6371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
64e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
65e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
6626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from changing Wi-Fi
672cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * access points. The default value is <code>false</code>.
68150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect in a managed profile.
6926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
7026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
7126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
72068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
73068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
74e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
75e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
7671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi";
77e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
78e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
7926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from installing applications.
8071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
8126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
8226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
8326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
84068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
85068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
86e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
87e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
8871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_INSTALL_APPS = "no_install_apps";
89e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
90e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
9126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from uninstalling applications.
9271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
9326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
9426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
9526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
96068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
97068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
98e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
99e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
10071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
101e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
10271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
103150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * Specifies if a user is disallowed from turning on location sharing.
10471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
105150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>In a managed profile, location sharing always reflects the primary user's setting, but
106150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * can be overridden and forced off by setting this restriction to true in the managed profile.
10726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
10826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
10926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
110068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
111068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
1126794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     * @see #getUserRestrictions()
1136794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
11471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_SHARE_LOCATION = "no_share_location";
1156794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
116a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
11726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from enabling the
118a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * "Unknown Sources" setting, that allows installation of apps from unknown sources.
119a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * The default value is <code>false</code>.
12026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
12126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
12226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
123068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
124068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
125a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
126a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
127a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
128a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
129a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
13026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring bluetooth.
1311c4c442e4540b16aed7acc345aea26ab101efbf8Nicolas Prevot     * This does <em>not</em> restrict the user from turning bluetooth on or off.
132a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * The default value is <code>false</code>.
133150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect in a managed profile.
13426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
13526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
13626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
137068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
138068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
139a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
140a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
141a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
142a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
143a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
14426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from transferring files over
145c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * USB. This can only be set by device owners and profile owners on the primary user.
146c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
14726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
14826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
14926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
150068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
151068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
152a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
153a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
154a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
155a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
156b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    /**
15726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring user
158b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * credentials. The default value is <code>false</code>.
15926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
16026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
16126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
162068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
163068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
164b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
165b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
166b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
167b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
168b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    /**
169150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * When set on the primary user this specifies if the user can remove other users.
170150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * When set on a secondary user, this specifies if the user can remove itself.
171150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * This restriction has no effect on managed profiles.
172150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * The default value is <code>false</code>.
17326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
17426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
17526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
176068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
177068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
178b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
179b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
180b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_REMOVE_USER = "no_remove_user";
181b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
182d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
18326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from enabling or
184d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * accessing debugging features. The default value is <code>false</code>.
18526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
18626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
18726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
188068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
189068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
190d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
191d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
192d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
193d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
194d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
19526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring VPN.
196d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * The default value is <code>false</code>.
197298f98fa234f353267ddc9c75d58e8cc542c25f1Nicolas Prevot     * This restriction has an effect in a managed profile only from
1980e3de6cacaffcfeda4d6353be61e2f1f9ed80705Dianne Hackborn     * {@link android.os.Build.VERSION_CODES#M}
19926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
20026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
20126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
202068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
203068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
204d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
205d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
206d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_VPN = "no_config_vpn";
207d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
208d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
20926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring Tethering
210c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * & portable hotspots. This can only be set by device owners and profile owners on the
211c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * primary user. The default value is <code>false</code>.
21226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
21326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
21426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
215068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
216068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
217d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
218d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
219d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering";
220d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
221d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
222e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * Specifies if a user is disallowed from resetting network settings
223e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * from Settings. This can only be set by device owners and profile owners on the primary user.
224e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * The default value is <code>false</code>.
225e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * <p/>This restriction has no effect on secondary users and managed profiles since only the
226e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * primary user can reset the network settings of the device.
227e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     *
228e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * <p/>Key for user restrictions.
229e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * <p/>Type: Boolean
230068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
231068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
232e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * @see #getUserRestrictions()
233e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     */
234e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott    public static final String DISALLOW_NETWORK_RESET = "no_network_reset";
235e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott
236e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott    /**
23726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from factory resetting
238c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * from Settings. This can only be set by device owners and profile owners on the primary user.
239c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
240150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect on secondary users and managed profiles since only the
241150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can factory reset the device.
24226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
24326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
24426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
245068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
246068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
247d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
248d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
249d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_FACTORY_RESET = "no_factory_reset";
250d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
251d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
25226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from adding new users and
253c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * profiles. This can only be set by device owners and profile owners on the primary user.
254c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
255150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect on secondary users and managed profiles since only the
256150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can add other users.
25726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
25826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
25926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
260068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
261068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
262d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
263d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
264d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_ADD_USER = "no_add_user";
265d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
266d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
26726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from disabling application
268d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * verification. The default value is <code>false</code>.
26926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
27026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
27126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
272068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
273068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
274d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
275d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
276d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps";
277d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
278d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
27926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring cell
280c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * broadcasts. This can only be set by device owners and profile owners on the primary user.
281c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
282150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect on secondary users and managed profiles since only the
283150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can configure cell broadcasts.
28426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
28526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
28626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
287068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
288068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
289d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
290d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
291d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts";
292d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
293d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
29426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring mobile
295c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * networks. This can only be set by device owners and profile owners on the primary user.
296c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
297150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect on secondary users and managed profiles since only the
298150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can configure mobile networks.
29926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
30026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
30126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
302068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
303068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
304d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
305d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
306d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks";
307d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
308d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
30926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from modifying
310c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * applications in Settings or launchers. The following actions will not be allowed when this
311c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * restriction is enabled:
312c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>uninstalling apps</li>
313c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>disabling apps</li>
314c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app caches</li>
315c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app data</li>
316c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>force stopping apps</li>
317c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app defaults</li>
318c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <p>
319c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * The default value is <code>false</code>.
32026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
32126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
32226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
323068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
324068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
325d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
326d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
32736fbc8d6453da438a8ab83352ff1bcfcba5f25b5Julia Reynolds    public static final String DISALLOW_APPS_CONTROL = "no_control_apps";
328d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
329394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
33026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from mounting
331c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * physical external media. This can only be set by device owners and profile owners on the
332c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * primary user. The default value is <code>false</code>.
33326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
33426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
33526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
336068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
337068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
338394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
339394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
340394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
341394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
342394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
34326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from adjusting microphone
344c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * volume. If set, the microphone will be muted. This can only be set by device owners
345c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * and profile owners on the primary user. The default value is <code>false</code>.
34626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
34726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
34826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
349068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
350068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
351394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
352394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
353394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
354394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
355394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
35626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from adjusting the master
357c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * volume. If set, the master volume will be muted. This can only be set by device owners
358c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * and profile owners on the primary user. The default value is <code>false</code>.
35926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
36026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
36126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
362068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
363068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
364394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
365394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
366394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume";
367394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
3689f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani    /**
36926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that the user is not allowed to make outgoing
370390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * phone calls. Emergency calls are still permitted.
371390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * The default value is <code>false</code>.
372150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect on managed profiles since call intents are normally
373150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * forwarded to the primary user.
37426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
37526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
37626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
377068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
378068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
379390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * @see #getUserRestrictions()
380390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     */
381390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls";
382390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani
383390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    /**
38426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that the user is not allowed to send or receive
385c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * SMS messages. The default value is <code>false</code>.
38626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
38726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
38826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
389068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
390068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
3919f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * @see #getUserRestrictions()
3929f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     */
393390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    public static final String DISALLOW_SMS = "no_sms";
3949f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani
3951c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk    /**
3962cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * Specifies if the user is not allowed to have fun. In some cases, the
3972cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * device owner may wish to prevent the user from experiencing amusement or
3982cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * joy while using the device. The default value is <code>false</code>.
3992cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     *
4002cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * <p/>Key for user restrictions.
4012cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * <p/>Type: Boolean
402068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
403068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
4042cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * @see #getUserRestrictions()
4052cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     */
4062cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey    public static final String DISALLOW_FUN = "no_fun";
4072cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey
4082cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey    /**
40926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that windows besides app windows should not be
4101c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * created. This will block the creation of the following types of windows.
4111c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_TOAST}</li>
4121c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_PHONE}</li>
4131c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li>
4141c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li>
4151c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li>
4161c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li>
4171c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     *
418c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * <p>This can only be set by device owners and profile owners on the primary user.
419c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
42026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
42126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
42226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
423068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
424068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
4251c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * @see #getUserRestrictions()
4261c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     */
4271c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk    public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows";
4281c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk
429f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot    /**
43026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if what is copied in the clipboard of this profile can
431f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be
432f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * pasted in this profile.
433f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * The default value is <code>false</code>.
43426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
43526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
43626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
437068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
438068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
439f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * @see #getUserRestrictions()
440f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     */
441f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot    public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste";
442f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot
44326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani    /**
44426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if the user is not allowed to use NFC to beam out data from apps.
44526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * The default value is <code>false</code>.
44626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
44726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
44826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
449068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
450068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
45126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * @see #getUserRestrictions()
45226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     */
45326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani    public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam";
45426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani
45553d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse    /**
456f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * Hidden user restriction to disallow access to wallpaper manager APIs. This user restriction
457f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * is always set for managed profiles.
458f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * @hide
459068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
460068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
461f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * @see #getUserRestrictions()
462f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     */
463f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz    public static final String DISALLOW_WALLPAPER = "no_wallpaper";
464f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz
465f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz    /**
466bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * Specifies if the user is not allowed to reboot the device into safe boot mode.
467bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * This can only be set by device owners and profile owners on the primary user.
468bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * The default value is <code>false</code>.
469bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     *
470bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * <p/>Key for user restrictions.
471bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * <p/>Type: Boolean
472068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
473068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
474bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * @see #getUserRestrictions()
475bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     */
476bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz    public static final String DISALLOW_SAFE_BOOT = "no_safe_boot";
477bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz
478bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz    /**
479b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * Specifies if a user is not allowed to record audio. This restriction is always enabled for
480b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * background users. The default value is <code>false</code>.
481b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     *
482068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
483068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
484b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * @see #getUserRestrictions()
485b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * @hide
486b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     */
487b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov    public static final String DISALLOW_RECORD_AUDIO = "no_record_audio";
488b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov
489b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov    /**
4909cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * Specifies if a user is not allowed to run in the background and should be stopped during
4919cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * user switch. The default value is <code>false</code>.
4929cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     *
4939cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * <p>This restriction can be set by device owners and profile owners.
4949cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     *
4959cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
4969cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
4979cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * @see #getUserRestrictions()
4989cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * @hide
4999cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     */
5009cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov    public static final String DISALLOW_RUN_IN_BACKGROUND = "no_run_in_background";
5019cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov
5029cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov    /**
503759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     * Specifies if a user is not allowed to use the camera.
504759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     *
505759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
506759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
507759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     * @see #getUserRestrictions()
508759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     * @hide
509759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     */
510759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki    public static final String DISALLOW_CAMERA = "no_camera";
511759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki
512759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki    /**
513f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot     * Allows apps in the parent profile to handle web links from the managed profile.
514f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot     *
5159edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * This user restriction has an effect only in a managed profile.
5169edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * If set:
5179edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * Intent filters of activities in the parent profile with action
5189edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * {@link android.content.Intent#ACTION_VIEW},
5199edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which
5209edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * define a host can handle intents from the managed profile.
5219edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * The default value is <code>false</code>.
5229edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     *
5239edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * <p/>Key for user restrictions.
5249edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * <p/>Type: Boolean
525068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
526068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
5279edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * @see #getUserRestrictions()
5289edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     */
529f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot    public static final String ALLOW_PARENT_PROFILE_APP_LINKING
530f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot            = "allow_parent_profile_app_linking";
5319edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot
5329edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot    /**
53353d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * Application restriction key that is used to indicate the pending arrival
53453d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * of real restrictions for the app.
53553d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     *
53653d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * <p>
53753d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * Applications that support restrictions should check for the presence of this key.
53853d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * A <code>true</code> value indicates that restrictions may be applied in the near
53953d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * future but are not available yet. It is the responsibility of any
54053d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * management application that sets this flag to update it when the final
54153d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * restrictions are enforced.
54253d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     *
54353d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * <p/>Key for application restrictions.
54453d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * <p/>Type: Boolean
545b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions(
546b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     *      android.content.ComponentName, String, Bundle)
547b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions(
548b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     *      android.content.ComponentName, String)
54953d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     */
55053d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse    public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
55153d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse
552655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
553655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
554655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
555655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2;
556655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
557655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_SUCCESS = -1;
558655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
5597e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /** @hide */
560c0688301de5feea94c8456b3b9b42c41d0045f03Amith Yamasani    public static UserManager get(Context context) {
561c0688301de5feea94c8456b3b9b42c41d0045f03Amith Yamasani        return (UserManager) context.getSystemService(Context.USER_SERVICE);
56227db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    }
563a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
564258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /** @hide */
565258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserManager(Context context, IUserManager service) {
566258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        mService = service;
567258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        mContext = context;
568258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
569258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
570258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
571258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns whether the system supports multiple users.
5721a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @return true if multiple users can be created by user, false if it is a single user device.
573e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @hide
574258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
5754673e7ea8d1f869910a9c0f9c211d4d27ad50b41Jeff Sharkey    public static boolean supportsMultipleUsers() {
5761a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        return getMaxSupportedUsers() > 1
5771a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                && SystemProperties.getBoolean("fw.show_multiuserui",
5781a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));
579258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
580258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
5816794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    /**
5827cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     * @hide
5837cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     * @return Whether the device is running with split system user. It means the system user and
5847cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     * primary user are two separate users. Previously system user and primary user are combined as
5857cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     * a single owner user.  see @link {android.os.UserHandle#USER_OWNER}
5867cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     */
5877cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen    public static boolean isSplitSystemUser() {
5887cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen        return SystemProperties.getBoolean("ro.fw.system_user_split", false);
5897cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen    }
5907cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen
5917cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen    /**
5925760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * Returns the user handle for the user that this process is running under.
593be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     *
5945760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * @return the user handle of this process.
595258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
5966794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
597258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public int getUserHandle() {
59879af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn        return UserHandle.myUserId();
599258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
600258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
601258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
6028832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * Returns the user name of the user making this call.  This call is only
6038832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * available to applications on the system image; it requires the
6048832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * MANAGE_USERS permission.
605258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the user name
606258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
607258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public String getUserName() {
608258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
609258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(getUserHandle()).name;
610258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
611258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user name", re);
612258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return "";
613258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
614258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
615258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
61667a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn    /**
617e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * Used to determine whether the user making this call is subject to
618e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * teleportations.
61967a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     *
620955d8d69ea6caabce1461dc25b339b9bf9dc61a6Dianne Hackborn     * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can
62167a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     * now automatically identify goats using advanced goat recognition technology.</p>
62267a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     *
62367a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     * @return Returns true if the user making this call is a goat.
624e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     */
625e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    public boolean isUserAGoat() {
626988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell        return mContext.getPackageManager()
627988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell                .isPackageAvailable("com.coffeestainstudios.goatsimulator");
628e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    }
629df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
630df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
63170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * Used to check if this process is running under the primary user. The primary user
63270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * is the first human user on a device.
63370f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     *
63470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * @return whether this process is running under the primary user.
63570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * @hide
63670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     */
63770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    public boolean isPrimaryUser() {
63870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        UserInfo user = getUserInfo(UserHandle.myUserId());
63970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        return user != null ? user.isPrimary() : false;
64070f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    }
64170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen
64270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    /**
6435760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * Used to check if this process is running under the system user. The system user
6445760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * is the initial user that is implicitly created on first boot and hosts most of the
6455760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * system services.
6465760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     *
6475760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * @return whether this process is running under the system user.
6485760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     */
6495760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani    public boolean isSystemUser() {
65070f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        return UserHandle.myUserId() == UserHandle.USER_SYSTEM;
6515760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani    }
6522b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen
6535760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani    /**
654462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani     * @hide
655462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani     * Returns whether the caller is running as an admin user. There can be more than one admin
656462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani     * user.
657462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani     */
658462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani    public boolean isAdminUser() {
6592b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen        return isUserAdmin(UserHandle.myUserId());
6602b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen    }
6612b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen
6622b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen    /**
6632b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen     * @hide
6642b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen     * Returns whether the provided user is an admin user. There can be more than one admin
6652b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen     * user.
6662b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen     */
6672b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen    public boolean isUserAdmin(int userId) {
6682b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen        UserInfo user = getUserInfo(userId);
6692b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen        return user != null && user.isAdmin();
670462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani    }
671462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani
672462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani    /**
673e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * Used to check if the user making this call is linked to another user. Linked users may have
67446bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani     * a reduced number of available apps, app restrictions and account restrictions.
675e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * @return whether the user making this call is a linked user
6762555dafce87e60fae28d71913730abf73e40fcd7Amith Yamasani     * @hide
677df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
678e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani    public boolean isLinkedUser() {
679df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
68071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani            return mService.isRestricted();
681df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
68246bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani            Log.w(TAG, "Could not check if user is limited ", re);
683df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            return false;
684df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
685df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
686df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
687258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
6881c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov     * Checks if specified user can have restricted profile.
6891c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov     * @hide
6901c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov     */
6911c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov    public boolean canHaveRestrictedProfile(int userId) {
6921c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov        try {
6931c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov            return mService.canHaveRestrictedProfile(userId);
6941c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov        } catch (RemoteException re) {
6951c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov            Log.w(TAG, "Could not check if user can have restricted profile", re);
6961c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov            return false;
6971c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov        }
6981c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov    }
6991c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov
7001c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov    /**
7011e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * Checks if the calling app is running as a guest user.
7021e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @return whether the caller is a guest user.
7031e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @hide
7041e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     */
7051e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    public boolean isGuestUser() {
7061e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        UserInfo user = getUserInfo(UserHandle.myUserId());
7071e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        return user != null ? user.isGuest() : false;
7081e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    }
7091e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani
7101e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    /**
7110e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * Checks if the calling app is running in a managed profile.
7120e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
7130e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     *
7140e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * @return whether the caller is in a managed profile.
7150e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * @hide
7160e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     */
7170e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    @SystemApi
7180e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    public boolean isManagedProfile() {
7190e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani        UserInfo user = getUserInfo(UserHandle.myUserId());
7200e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani        return user != null ? user.isManagedProfile() : false;
7210e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    }
7220e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani
7230e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    /**
724c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     * Checks if the calling app is running as an ephemeral user.
725c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     *
726c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     * @return whether the caller is an ephemeral user.
727c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     * @hide
728c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     */
729c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova    public boolean isEphemeralUser() {
730c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova        return isUserEphemeral(UserHandle.myUserId());
731c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova    }
732c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova
733c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova    /**
734c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     * Returns whether the specified user is ephemeral.
735c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     * @hide
736c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     */
737c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova    public boolean isUserEphemeral(int userId) {
738c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova        final UserInfo user = getUserInfo(userId);
739c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova        return user != null && user.isEphemeral();
740c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova    }
741c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova
742c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova    /**
743a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running.  This means that
744a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * the user is in the "started" state, not "stopped" -- it is currently
745a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * allowed to run code through scheduled alarms, receiving broadcasts,
746a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * etc.  A started user may be either the current foreground user or a
747a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * background user; the result here does not distinguish between the two.
748a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
749a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
750a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunning(UserHandle user) {
751a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
752a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return ActivityManagerNative.getDefault().isUserRunning(
753e17ac1569793c333bb4dce86607a342e7c982ae7Jeff Sharkey                    user.getIdentifier(), 0);
754a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        } catch (RemoteException e) {
755a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return false;
756a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
757a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
758a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
759a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    /**
760a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running <em>or</em> stopping.
761a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * This is like {@link #isUserRunning(UserHandle)}, but will also return
762a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * true if the user had been running but is in the process of being stopped
763a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * (but is not yet fully stopped, and still running some code).
764a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
765a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
766a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunningOrStopping(UserHandle user) {
767a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
768e17ac1569793c333bb4dce86607a342e7c982ae7Jeff Sharkey            // TODO: reconcile stopped vs stopping?
769a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return ActivityManagerNative.getDefault().isUserRunning(
770e17ac1569793c333bb4dce86607a342e7c982ae7Jeff Sharkey                    user.getIdentifier(), ActivityManager.FLAG_OR_STOPPED);
771a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        } catch (RemoteException e) {
772a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return false;
773a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
774a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
775a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
776a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    /**
7779d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey     * Return whether the given user is running in a "locked" state. A user
7789d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey     * is unlocked only after they've entered their credentials (such as a lock
7799d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey     * pattern or PIN), and credential-encrypted private app data storage is
7809d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey     * available.
7819d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey     *
7829d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey     * @param user to retrieve the unlocked state for.
7839d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey     */
7849d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey    public boolean isUserRunningAndLocked(UserHandle user) {
7859d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey        try {
7869d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey            return ActivityManagerNative.getDefault().isUserRunning(
7879d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey                    user.getIdentifier(), ActivityManager.FLAG_AND_LOCKED);
7889d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey        } catch (RemoteException e) {
7899d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey            return false;
7909d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey        }
7919d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey    }
7929d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey
7939d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey    /**
7940825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey     * Return whether the given user is running in an "unlocked" state. A user
7950825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey     * is unlocked only after they've entered their credentials (such as a lock
7960825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey     * pattern or PIN), and credential-encrypted private app data storage is
7970825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey     * available.
7980825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey     *
7990825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey     * @param user to retrieve the unlocked state for.
8000825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey     */
8019d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey    public boolean isUserRunningAndUnlocked(UserHandle user) {
8020825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey        try {
8030825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey            return ActivityManagerNative.getDefault().isUserRunning(
8040825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey                    user.getIdentifier(), ActivityManager.FLAG_AND_UNLOCKED);
8050825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey        } catch (RemoteException e) {
8060825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey            return false;
8070825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey        }
8080825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey    }
8090825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey
8100825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey    /**
811258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the UserInfo object describing a specific user.
8121952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
813258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user handle of the user whose information is being requested.
814258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for a specific user.
815258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
816b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
817258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserInfo getUserInfo(int userHandle) {
818258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
819258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(userHandle);
820258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
821258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user info", re);
822258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
823258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
824258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
825258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
82671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
82771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on this user.
82871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
82971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
830e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions() {
831e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        return getUserRestrictions(Process.myUserHandle());
832e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
833e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
83471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
83571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
83671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
83771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
83871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
839e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions(UserHandle userHandle) {
840e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        try {
841e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            return mService.getUserRestrictions(userHandle.getIdentifier());
842e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        } catch (RemoteException re) {
843e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            Log.w(TAG, "Could not get user restrictions", re);
844e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            return Bundle.EMPTY;
845e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        }
846e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
847e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
8483bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     /**
8493bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     * @hide
8503bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     * Returns whether the given user has been disallowed from performing certain actions
8513bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     * or setting certain settings through UserManager. This method disregards restrictions
8523bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     * set by device policy.
8533bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     * @param restrictionKey the string key representing the restriction
8543bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
8553bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     */
8563bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban    public boolean hasBaseUserRestriction(String restrictionKey, UserHandle userHandle) {
8573bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban        try {
8583bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban            return mService.hasBaseUserRestriction(restrictionKey, userHandle.getIdentifier());
8593bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban        } catch (RemoteException re) {
8603bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban            Log.w(TAG, "Could not get base user restrictions for user " +
8613bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban                    userHandle.getIdentifier(), re);
8623bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban            return false;
8633bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban        }
8643bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban    }
8653bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban
86671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
867a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki     * This will no longer work.  Device owners and profile owners should use
868a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki     * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead.
86971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
870a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki    // System apps should use UserManager.setUserRestriction() instead.
8713d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
872e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions) {
873068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki        throw new UnsupportedOperationException("This method is no longer supported");
874e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
875e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
87671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
877a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki     * This will no longer work.  Device owners and profile owners should use
878a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki     * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead.
87971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
880a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki    // System apps should use UserManager.setUserRestriction() instead.
8813d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
882e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
883068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki        throw new UnsupportedOperationException("This method is no longer supported");
884e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
885e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
88671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
88771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction.
888be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
88971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
89071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
8913d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
8923d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
8933d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
8943d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
89571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
8963d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
89771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public void setUserRestriction(String key, boolean value) {
898068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki        setUserRestriction(key, value, Process.myUserHandle());
89971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    }
90071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani
90171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
90271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @hide
90371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction on a specific user.
904be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
90571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
90671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
90771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the user whose restriction is to be changed.
9083d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
9093d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
9103d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
9113d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
91271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
9133d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
9146794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
915b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov        try {
916b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov            mService.setUserRestriction(key, value, userHandle.getIdentifier());
917b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov        } catch (RemoteException re) {
918b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov            Log.w(TAG, "Could not set user restriction", re);
919b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov        }
9206794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    }
9216794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
922258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
923a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Returns whether the current user has been disallowed from performing certain actions
924a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * or setting certain settings.
9252b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     *
9262b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     * @param restrictionKey The string key representing the restriction.
9272b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     * @return {@code true} if the current user has the given restriction, {@code false} otherwise.
928a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
929a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public boolean hasUserRestriction(String restrictionKey) {
930b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie        return hasUserRestriction(restrictionKey, Process.myUserHandle());
931b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    }
932b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie
933b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    /**
934b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @hide
935b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * Returns whether the given user has been disallowed from performing certain actions
936b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * or setting certain settings.
937b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param restrictionKey the string key representing the restriction
938b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
939b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     */
940b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
9418cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        try {
9428cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani            return mService.hasUserRestriction(restrictionKey,
9438cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani                    userHandle.getIdentifier());
9448cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        } catch (RemoteException re) {
9458cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani            Log.w(TAG, "Could not check user restrictions", re);
9468cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani            return false;
9478cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        }
948a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    }
949a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
950a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
95133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the serial number for a user.  This is a device-unique
952b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * number assigned to that user; if the user is deleted and then a new
953b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * user created, the new users will not be given the same serial number.
95433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param user The user whose serial number is to be retrieved.
955b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * @return The serial number of the given user; returns -1 if the
956b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * given UserHandle does not exist.
95733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getUserForSerialNumber(long)
95833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
95933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public long getSerialNumberForUser(UserHandle user) {
96033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return getUserSerialNumber(user.getIdentifier());
96133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
96233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
96333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
96433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the user associated with a serial number previously
96533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * returned by {@link #getSerialNumberForUser(UserHandle)}.
96633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param serialNumber The serial number of the user that is being
96733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * retrieved.
96833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @return Return the user associated with the serial number, or null
96933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * if there is not one.
97033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getSerialNumberForUser(UserHandle)
97133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
97233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public UserHandle getUserForSerialNumber(long serialNumber) {
973ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov        int ident = getUserHandle((int) serialNumber);
97433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return ident >= 0 ? new UserHandle(ident) : null;
97533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
97633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
97733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
978cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen     * Creates a user with the specified name and options. For non-admin users, default user
979cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen     * restrictions are going to be applied.
9801952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
981258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
982258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the user's name
983258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param flags flags that identify the type of user and other properties.
984258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @see UserInfo
985258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
986258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for the created user, or null if the user could not be created.
987258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
988258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
989258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserInfo createUser(String name, int flags) {
990cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen        UserInfo user = null;
991258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
992cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen            user = mService.createUser(name, flags);
993cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen            if (user != null && !user.isAdmin()) {
994068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki                mService.setUserRestriction(DISALLOW_SMS, true, user.id);
995068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki                mService.setUserRestriction(DISALLOW_OUTGOING_CALLS, true, user.id);
996cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen            }
997258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
998258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not create a user", re);
999258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1000cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen        return user;
1001258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1002258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1003258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
10041e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * Creates a guest user and configures it.
10051e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @param context an application context
10061e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @param name the name to set for the user
10071e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @hide
10081e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     */
10091e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    public UserInfo createGuest(Context context, String name) {
1010068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki        UserInfo guest = null;
1011068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki        try {
1012068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki            guest = mService.createUser(name, UserInfo.FLAG_GUEST);
1013068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki            if (guest != null) {
1014068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki                Settings.Secure.putStringForUser(context.getContentResolver(),
1015068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki                        Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
1016bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani            }
1017068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki        } catch (RemoteException re) {
1018068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki            Log.w(TAG, "Could not create a user", re);
10191e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        }
10201e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        return guest;
10211e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    }
10221e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani
1023aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani    /**
10242a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Creates a user with the specified name and options as a profile of another user.
1025a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1026a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     *
1027a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @param name the user's name
1028a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @param flags flags that identify the type of user and other properties.
1029a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @see UserInfo
10302a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @param userHandle new user will be a profile of this use.
1031a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     *
1032a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @return the UserInfo object for the created user, or null if the user could not be created.
1033a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @hide
1034a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     */
10352a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy    public UserInfo createProfileForUser(String name, int flags, int userHandle) {
1036a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        try {
10372a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy            return mService.createProfileForUser(name, flags, userHandle);
1038a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        } catch (RemoteException re) {
1039a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            Log.w(TAG, "Could not create a user", re);
1040a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            return null;
1041a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        }
1042a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    }
1043a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy
1044a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    /**
104502cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov     * Creates a restricted profile with the specified name. This method also sets necessary
104602cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov     * restrictions and adds shared accounts.
104706a484adb93c6c969321147b07112684383305f6Fyodor Kupolov     *
104806a484adb93c6c969321147b07112684383305f6Fyodor Kupolov     * @param name profile's name
104906a484adb93c6c969321147b07112684383305f6Fyodor Kupolov     * @return UserInfo object for the created user, or null if the user could not be created.
105006a484adb93c6c969321147b07112684383305f6Fyodor Kupolov     * @hide
105106a484adb93c6c969321147b07112684383305f6Fyodor Kupolov     */
105206a484adb93c6c969321147b07112684383305f6Fyodor Kupolov    public UserInfo createRestrictedProfile(String name) {
105306a484adb93c6c969321147b07112684383305f6Fyodor Kupolov        try {
105402cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov            UserHandle parentUserHandle = Process.myUserHandle();
105502cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov            UserInfo user = mService.createRestrictedProfile(name,
105602cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov                    parentUserHandle.getIdentifier());
105702cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov            if (user != null) {
105802cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov                AccountManager.get(mContext).addSharedAccountsFromParentUser(parentUserHandle,
105902cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov                        UserHandle.of(user.id));
106006a484adb93c6c969321147b07112684383305f6Fyodor Kupolov            }
106102cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov            return user;
106206a484adb93c6c969321147b07112684383305f6Fyodor Kupolov        } catch (RemoteException e) {
106306a484adb93c6c969321147b07112684383305f6Fyodor Kupolov            Log.w(TAG, "Could not create a restricted profile", e);
106406a484adb93c6c969321147b07112684383305f6Fyodor Kupolov        }
106506a484adb93c6c969321147b07112684383305f6Fyodor Kupolov        return null;
106606a484adb93c6c969321147b07112684383305f6Fyodor Kupolov    }
106706a484adb93c6c969321147b07112684383305f6Fyodor Kupolov
106806a484adb93c6c969321147b07112684383305f6Fyodor Kupolov    /**
10691df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @hide
10701df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * Marks the guest user for deletion to allow a new guest to be created before deleting
10711df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * the current user who is a guest.
10721df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @param userHandle
10731df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @return
10741df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     */
10751df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    public boolean markGuestForDeletion(int userHandle) {
10761df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        try {
10771df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani            return mService.markGuestForDeletion(userHandle);
10781df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        } catch (RemoteException re) {
10791df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani            Log.w(TAG, "Could not mark guest for deletion", re);
10801df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani            return false;
10811df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        }
10821df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    }
10831df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani
10841df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    /**
1085df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Sets the user as enabled, if such an user exists.
1086df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1087df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Note that the default is true, it's only that managed profiles might not be enabled.
1088df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     *
1089df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * @param userHandle the id of the profile to enable
1090df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * @hide
1091df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     */
1092df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    public void setUserEnabled(int userHandle) {
1093df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        try {
1094df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina            mService.setUserEnabled(userHandle);
1095df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        } catch (RemoteException e) {
1096df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina            Log.w(TAG, "Could not enable the profile", e);
1097df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        }
1098df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    }
1099df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina
1100df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    /**
1101b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * Return the number of users currently created on the device.
1102b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
1103b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    public int getUserCount() {
1104b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        List<UserInfo> users = getUsers();
1105b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        return users != null ? users.size() : 1;
1106b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    }
1107b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn
1108b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    /**
1109258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns information for all users on this device.
11101952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1111258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the list of users that were created.
1112258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1113258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1114258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public List<UserInfo> getUsers() {
1115258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1116920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(false);
1117920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        } catch (RemoteException re) {
1118920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            Log.w(TAG, "Could not get user list", re);
1119920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return null;
1120920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        }
1121920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    }
1122920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani
1123920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    /**
112470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * Returns information for Primary user.
112570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
112670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     *
112770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * @return the Primary user, null if not found.
112870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * @hide
112970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     */
11307cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen    public @Nullable UserInfo getPrimaryUser() {
113170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        try {
113270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen            return mService.getPrimaryUser();
113370f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        } catch (RemoteException re) {
113470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen            Log.w(TAG, "Could not get Primary user", re);
113570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen            return null;
113670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        }
113770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    }
113870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen
113970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    /**
114095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS
114195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * permission.
114295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     *
114395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * @return true if more users can be added, false if limit has been reached.
114495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * @hide
114595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     */
114695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    public boolean canAddMoreUsers() {
114795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        final List<UserInfo> users = getUsers(true);
114895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        final int totalUserCount = users.size();
114995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        int aliveUserCount = 0;
115095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        for (int i = 0; i < totalUserCount; i++) {
115195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            UserInfo user = users.get(i);
115295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            if (!user.isGuest()) {
115395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani                aliveUserCount++;
115495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            }
115595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        }
115695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        return aliveUserCount < getMaxSupportedUsers();
115795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    }
115895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani
115995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    /**
116072434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS
116172434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * permission.
116207387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot     * if allowedToRemoveOne is true and if the user already has a managed profile, then return if
116307387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot     * we could add a new managed profile to this user after removing the existing one.
116472434b7088591828082dd952496d523ef3622de2Nicolas Prevot     *
116572434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * @return true if more managed profiles can be added, false if limit has been reached.
116672434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * @hide
116772434b7088591828082dd952496d523ef3622de2Nicolas Prevot     */
116807387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot    public boolean canAddMoreManagedProfiles(int userId, boolean allowedToRemoveOne) {
116972434b7088591828082dd952496d523ef3622de2Nicolas Prevot        try {
117007387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot            return mService.canAddMoreManagedProfiles(userId, allowedToRemoveOne);
117172434b7088591828082dd952496d523ef3622de2Nicolas Prevot        } catch (RemoteException re) {
117272434b7088591828082dd952496d523ef3622de2Nicolas Prevot            Log.w(TAG, "Could not check if we can add more managed profiles", re);
117372434b7088591828082dd952496d523ef3622de2Nicolas Prevot            return false;
117472434b7088591828082dd952496d523ef3622de2Nicolas Prevot        }
117572434b7088591828082dd952496d523ef3622de2Nicolas Prevot    }
117672434b7088591828082dd952496d523ef3622de2Nicolas Prevot
117772434b7088591828082dd952496d523ef3622de2Nicolas Prevot    /**
11782a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Returns list of the profiles of userHandle including
11792a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * userHandle itself.
11804f7e2e334e4ca5f1a67baf4bdd40cd080b954161Amith Yamasani     * Note that this returns both enabled and not enabled profiles. See
11817f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * {@link #getEnabledProfiles(int)} if you need only the enabled ones.
11824f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *
11832a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
11842a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @param userHandle profiles of this user will be returned.
11852a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @return the list of profiles.
11862a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @hide
11872a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     */
11882a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy    public List<UserInfo> getProfiles(int userHandle) {
1189a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        try {
1190385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            return mService.getProfiles(userHandle, false /* enabledOnly */);
1191a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        } catch (RemoteException re) {
1192a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            Log.w(TAG, "Could not get user list", re);
1193a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            return null;
1194a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        }
1195a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    }
1196a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy
1197a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    /**
1198fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1199fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     * @param userId one of the two user ids to check.
1200fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     * @param otherUserId one of the two user ids to check.
1201fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     * @return true if the two user ids are in the same profile group.
1202fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     * @hide
1203fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     */
1204fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen    public boolean isSameProfileGroup(int userId, int otherUserId) {
1205fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen        try {
1206fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen            return mService.isSameProfileGroup(userId, otherUserId);
1207fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen        } catch (RemoteException re) {
1208fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen            Log.w(TAG, "Could not get user list", re);
1209fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen            return false;
1210fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen        }
1211fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen    }
1212fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen
1213fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen    /**
12147f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * Returns list of the profiles of userHandle including
12157f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * userHandle itself.
12167f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * Note that this returns only enabled.
12177f75da2405cd910854448bb3801f776e036f926aRuben Brunk     *
12187f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
12197f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * @param userHandle profiles of this user will be returned.
12207f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * @return the list of profiles.
12217f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * @hide
12227f75da2405cd910854448bb3801f776e036f926aRuben Brunk     */
12237f75da2405cd910854448bb3801f776e036f926aRuben Brunk    public List<UserInfo> getEnabledProfiles(int userHandle) {
12247f75da2405cd910854448bb3801f776e036f926aRuben Brunk        try {
12257f75da2405cd910854448bb3801f776e036f926aRuben Brunk            return mService.getProfiles(userHandle, true /* enabledOnly */);
12267f75da2405cd910854448bb3801f776e036f926aRuben Brunk        } catch (RemoteException re) {
12277f75da2405cd910854448bb3801f776e036f926aRuben Brunk            Log.w(TAG, "Could not get user list", re);
12287f75da2405cd910854448bb3801f776e036f926aRuben Brunk            return null;
12297f75da2405cd910854448bb3801f776e036f926aRuben Brunk        }
12307f75da2405cd910854448bb3801f776e036f926aRuben Brunk    }
12317f75da2405cd910854448bb3801f776e036f926aRuben Brunk
12327f75da2405cd910854448bb3801f776e036f926aRuben Brunk    /**
1233be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns a list of UserHandles for profiles associated with the user that the calling process
1234be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * is running on, including the user itself.
12354f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *
12364f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * @return A non-empty list of UserHandles associated with the calling user.
12374f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     */
12384f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    public List<UserHandle> getUserProfiles() {
12394f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        ArrayList<UserHandle> profiles = new ArrayList<UserHandle>();
12402b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen        List<UserInfo> users;
1241385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        try {
1242f2e7b3f56ae0ea9f49b5c50413b9be71d5249d6dAlexandra Gherghina            users = mService.getProfiles(UserHandle.myUserId(), true /* enabledOnly */);
1243385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        } catch (RemoteException re) {
1244385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            Log.w(TAG, "Could not get user list", re);
1245385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            return null;
1246385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        }
12474f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        for (UserInfo info : users) {
12484f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            UserHandle userHandle = new UserHandle(info.id);
12494f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            profiles.add(userHandle);
12504f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        }
12514f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        return profiles;
12524f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
12534f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
12547dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani    /**
1255c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     * Returns the device credential owner id of the profile from
1256c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     * which this method is called, or userHandle if called from a user that
1257c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     * is not a profile.
1258c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     *
1259c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     * @hide
1260c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     */
1261c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales    public int getCredentialOwnerProfile(int userHandle) {
1262c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales        try {
1263c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales            return mService.getCredentialOwnerProfile(userHandle);
1264c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales        } catch (RemoteException re) {
1265c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales            Log.w(TAG, "Could not get credential owner", re);
1266c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales            return -1;
1267c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales        }
1268c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales    }
1269c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales
1270c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales    /**
1271be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns the parent of the profile which this method is called from
1272be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * or null if called from a user that is not a profile.
1273be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     *
1274be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * @hide
1275be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     */
1276be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    public UserInfo getProfileParent(int userHandle) {
1277be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        try {
1278be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            return mService.getProfileParent(userHandle);
1279be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        } catch (RemoteException re) {
1280be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            Log.w(TAG, "Could not get profile parent", re);
1281be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            return null;
1282be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        }
1283be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    }
1284be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel
1285be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    /**
12860a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * Set quiet mode of a managed profile.
12870a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     *
12880a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * @param userHandle The user handle of the profile.
12890a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * @param enableQuietMode Whether quiet mode should be enabled or disabled.
12900a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * @hide
12910a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     */
12920a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu    public void setQuietModeEnabled(int userHandle, boolean enableQuietMode) {
12930a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu        try {
12940a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu            mService.setQuietModeEnabled(userHandle, enableQuietMode);
12950a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu        } catch (RemoteException e) {
12960a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu            Log.w(TAG, "Could not change the profile's quiet mode", e);
12970a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu        }
12980a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu    }
12990a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu
13000a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu    /**
13010a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * Returns whether the given profile is in quiet mode or not.
13020a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     *
13030a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * @param userHandle The user handle of the profile to be queried.
13040a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * @return true if the profile is in quiet mode, false otherwise.
13050a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     */
13060a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu    public boolean isQuietModeEnabled(UserHandle userHandle) {
13070a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu        try {
13080a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu            return mService.isQuietModeEnabled(userHandle.getIdentifier());
13090a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu        } catch (RemoteException e) {
13100a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu            Log.w(TAG, "Could not query the profile's quiet mode", e);
13110a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu        }
13120a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu        return false;
13130a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu    }
13140a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu
13150a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu    /**
13167dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * If the target user is a managed profile of the calling user or the caller
13177dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * is itself a managed profile, then this returns a badged copy of the given
1318c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * icon to be able to distinguish it from the original icon. For badging an
1319c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * arbitrary drawable use {@link #getBadgedDrawableForUser(
1320c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
1321c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * <p>
1322c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the original drawable is a BitmapDrawable and the backing bitmap is
1323c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
1324c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is performed in place and the original drawable is returned.
1325c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * </p>
1326c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *
1327c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param icon The icon to badge.
1328c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param user The target user.
1329c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @return A drawable that combines the original icon and a badge as
1330c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         determined by the system.
1331c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
1332c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     */
1333c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) {
1334c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedIcon(icon, user);
1335c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    }
1336c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav
1337c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    /**
1338c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the target user is a managed profile of the calling user or the caller
1339c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is itself a managed profile, then this returns a badged copy of the given
1340c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * drawable allowing the user to distinguish it from the original drawable.
1341c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * The caller can specify the location in the bounds of the drawable to be
1342c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * badged where the badge should be applied as well as the density of the
1343c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * badge to be used.
1344c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * <p>
1345c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the original drawable is a BitmapDrawable and the backing bitmap is
1346c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
1347c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is performed in place and the original drawable is returned.
1348c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * </p>
1349c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *
1350c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgedDrawable The drawable to badge.
1351c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param user The target user.
1352c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgeLocation Where in the bounds of the badged drawable to place
1353c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         the badge. If not provided, the badge is applied on top of the entire
1354c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         drawable being badged.
1355c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgeDensity The optional desired density for the badge as per
1356c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         {@link android.util.DisplayMetrics#densityDpi}. If not provided,
1357c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         the density of the display is used.
1358c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @return A drawable that combines the original drawable and a badge as
1359c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         determined by the system.
1360c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
1361c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     */
1362c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user,
1363c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            Rect badgeLocation, int badgeDensity) {
1364c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user,
1365c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav                badgeLocation, badgeDensity);
13664f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
13674f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
1368701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    /**
1369701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * If the target user is a managed profile of the calling user or the caller
1370f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * is itself a managed profile, then this returns a copy of the label with
1371f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * badging for accessibility services like talkback. E.g. passing in "Email"
1372f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * and it might return "Work Email" for Email in the work profile.
1373f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     *
1374f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @param label The label to change.
1375f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @param user The target user.
1376f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @return A label that combines the original label and a badge as
1377f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     *         determined by the system.
1378c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
1379f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     */
1380237aecd18d0edf56c038761f570758c310c9e6dfKenny Guy    public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) {
1381c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedLabel(label, user);
13824f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
13834f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
13844f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    /**
13854f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * Returns information for all users on this device. Requires
13864f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * {@link android.Manifest.permission#MANAGE_USERS} permission.
1387394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     *
13884f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * @param excludeDying specify if the list should exclude users being
13894f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *            removed.
1390920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @return the list of users that were created.
1391920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @hide
1392920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     */
1393920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    public List<UserInfo> getUsers(boolean excludeDying) {
1394920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        try {
1395920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(excludeDying);
1396258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1397258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user list", re);
1398258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
1399258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1400258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1401258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1402258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
1403258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Removes a user and all associated data.
14041952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1405258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the integer handle of the user, where 0 is the primary user.
1406258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1407258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1408258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public boolean removeUser(int userHandle) {
1409258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1410258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.removeUser(userHandle);
1411258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1412258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not remove user ", re);
1413258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return false;
1414258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1415258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1416258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1417258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
1418258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Updates the user's name.
14191952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1420258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
1421258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user's integer handle
1422258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the new name for the user
1423258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1424258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1425258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public void setUserName(int userHandle, String name) {
1426258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1427258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            mService.setUserName(userHandle, name);
1428258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1429258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not set the user name ", re);
1430258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1431258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1432258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1433258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
1434e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * Sets the user's photo.
1435258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user for whom to change the photo.
1436e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @param icon the bitmap to set as the photo.
1437258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1438258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1439e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani    public void setUserIcon(int userHandle, Bitmap icon) {
1440258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1441e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani            mService.setUserIcon(userHandle, icon);
1442258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1443258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not set the user icon ", re);
1444258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1445258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1446258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1447258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
14483b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * Returns a file descriptor for the user's photo. PNG data can be read from this file.
14493b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @param userHandle the user whose photo we want to read.
1450e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
145164d4dca63f65e4c7d4a829c85ff6670bdd34e2ebAlexandra Gherghina     * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
14523b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @hide
14533b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     */
1454e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani    public Bitmap getUserIcon(int userHandle) {
14553b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        try {
14561bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos            ParcelFileDescriptor fd = mService.getUserIcon(userHandle);
14571bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos            if (fd != null) {
14581bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                try {
14591bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
14601bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                } finally {
14611bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    try {
14621bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                        fd.close();
14631bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    } catch (IOException e) {
14641bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    }
14651bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                }
14661bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos            }
14673b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        } catch (RemoteException re) {
1468e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani            Log.w(TAG, "Could not get the user icon ", re);
14693b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        }
14701bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos        return null;
14713b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    }
14723b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani
14733b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    /**
1474258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the maximum number of users that can be created on this device. A return value
1475258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * of 1 means that it is a single user device.
1476258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1477a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @return a value greater than or equal to 1
1478258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
147927bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey    public static int getMaxSupportedUsers() {
1480ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        // Don't allow multiple users on certain builds
1481ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        if (android.os.Build.ID.startsWith("JVP")) return 1;
1482409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn        // Svelte devices don't get multi-user.
1483409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn        if (ActivityManager.isLowRamDeviceStatic()) return 1;
148427bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey        return SystemProperties.getInt("fw.max_users",
148527bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey                Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
1486258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
14872a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
14882a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
1489cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov     * Returns true if the user switcher should be shown, this will be if device supports multi-user
1490cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov     * and there are at least 2 users available that are not managed profiles.
14911a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @hide
14921a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @return true if user switcher should be shown.
14931a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     */
14941a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    public boolean isUserSwitcherEnabled() {
1495cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov        if (!supportsMultipleUsers()) {
1496cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov            return false;
1497cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov        }
14981a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        List<UserInfo> users = getUsers(true);
14991a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        if (users == null) {
15001a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy           return false;
15011a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        }
15021a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        int switchableUserCount = 0;
15031a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        for (UserInfo user : users) {
15047cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen            if (user.supportsSwitchToByUser()) {
15051a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                ++switchableUserCount;
15061a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy            }
15071a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        }
1508cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov        final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class)
1509cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov                .getGuestUserDisabled(null);
1510a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani        return switchableUserCount > 1 || guestEnabled;
15111a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    }
15121a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy
15131a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    /**
15142a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a serial number on this device for a given userHandle. User handles can be recycled
15152a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * when deleting and creating users, but serial numbers are not reused until the device is wiped.
15162a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userHandle
15172a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return a serial number associated with that user, or -1 if the userHandle is not valid.
15182a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
15192a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
15202a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    public int getUserSerialNumber(int userHandle) {
15212a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
15222a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserSerialNumber(userHandle);
15232a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
15242a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            Log.w(TAG, "Could not get serial number for user " + userHandle);
15252a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
15262a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        return -1;
15272a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
15282a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
15292a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
15302a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a userHandle on this device for a given user serial number. User handles can be
15312a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * recycled when deleting and creating users, but serial numbers are not reused until the device
15322a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is wiped.
15332a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userSerialNumber
15342a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return the userHandle associated with that user serial number, or -1 if the serial number
15352a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is not valid.
15362a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
15372a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
15382a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    public int getUserHandle(int userSerialNumber) {
15392a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
15402a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserHandle(userSerialNumber);
15412a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
15422a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            Log.w(TAG, "Could not get userHandle for user " + userSerialNumber);
15432a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
15442a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        return -1;
15452a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
15466794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
15477e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /**
15487e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * Returns a Bundle containing any saved application restrictions for this user, for the
15497e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * given package name. Only an application with this package name can call this method.
15507e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * @param packageName the package name of the calling application
15517e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * @return a Bundle with the restrictions as key/value pairs, or null if there are no
15527e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * saved restrictions. The values can be of type Boolean, String or String[], depending
15537e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * on the restriction type, as defined by the application.
15547e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     */
15557e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName) {
15567e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        try {
15577e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictions(packageName);
15587e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        } catch (RemoteException re) {
15597e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            Log.w(TAG, "Could not get application restrictions for package " + packageName);
15607e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        }
15617e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        return null;
15627e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    }
1563df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
1564df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
1565df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
1566df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
15677e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
1568df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
15697e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
1570df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
1571df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier());
1572df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
1573df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        return null;
1574df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
1575df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
1576df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
1577df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
1578df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
15797e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public void setApplicationRestrictions(String packageName, Bundle restrictions,
1580df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            UserHandle user) {
1581df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
15827e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
1583df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
1584df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier());
1585df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
1586df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
1587655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
1588655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
1589d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * Sets a new challenge PIN for restrictions. This is only for use by pre-installed
1590d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * apps and requires the MANAGE_USERS permission.
1591d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @param newPin the PIN to use for challenge dialogs.
1592d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @return Returns true if the challenge PIN was set successfully.
1593ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov     * @deprecated The restrictions PIN functionality is no longer provided by the system.
1594ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov     * This method is preserved for backwards compatibility reasons and always returns false.
1595655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
1596d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public boolean setRestrictionsChallenge(String newPin) {
1597655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return false;
1598655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
15991a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani
1600e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    /**
1601e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * @hide
1602e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * Set restrictions that should apply to any future guest user that's created.
1603e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     */
1604e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    public void setDefaultGuestRestrictions(Bundle restrictions) {
1605e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        try {
1606e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            mService.setDefaultGuestRestrictions(restrictions);
1607e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        } catch (RemoteException re) {
1608e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            Log.w(TAG, "Could not set guest restrictions");
1609e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        }
1610e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    }
1611e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani
1612e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    /**
1613e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * @hide
1614e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * Gets the default guest restrictions.
1615e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     */
1616e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    public Bundle getDefaultGuestRestrictions() {
1617e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        try {
1618e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            return mService.getDefaultGuestRestrictions();
1619e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        } catch (RemoteException re) {
1620e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            Log.w(TAG, "Could not set guest restrictions");
1621e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        }
1622e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        return new Bundle();
1623e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    }
1624ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov
1625ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov    /**
1626ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     * Returns creation time of the user or of a managed profile associated with the calling user.
1627ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     * @param userHandle user handle of the user or a managed profile associated with the
1628ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     *                   calling user.
1629ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     * @return creation time in milliseconds since Epoch time.
1630ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     */
1631385de624aa990266ffbaf70711ac8a330569429eFyodor Kupolov    public long getUserCreationTime(UserHandle userHandle) {
1632ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov        try {
1633385de624aa990266ffbaf70711ac8a330569429eFyodor Kupolov            return mService.getUserCreationTime(userHandle.getIdentifier());
1634ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov        } catch (RemoteException re) {
1635ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov            Log.w(TAG, "Could not get user creation time", re);
1636ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov            return 0;
1637ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov        }
1638ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov    }
1639258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani}
1640