UserManager.java revision c0688301de5feea94c8456b3b9b42c41d0045f03
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;
24258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.Context;
25258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.pm.UserInfo;
2627bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkeyimport android.content.res.Resources;
276794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport android.graphics.Bitmap;
281bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roosimport android.graphics.BitmapFactory;
294f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.Rect;
304f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.drawable.Drawable;
311e9c21871e81642669079cd290ef47818a3165bdAmith Yamasaniimport android.provider.Settings;
32258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.util.Log;
331c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monkimport android.view.WindowManager.LayoutParams;
34258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
356794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport com.android.internal.R;
366794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
371bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roosimport java.io.IOException;
384f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport java.util.ArrayList;
39258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport java.util.List;
40258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
41258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/**
42258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Manages users and user details on a multi-user system.
43258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */
44258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipublic class UserManager {
45258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
46258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private static String TAG = "UserManager";
47258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private final IUserManager mService;
48258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private final Context mContext;
49258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
50e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
5153019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov     * Specifies if a user is disallowed from adding and removing accounts, unless they are
5253019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov     * {@link android.accounts.AccountManager#addAccountExplicitly programmatically} added by
5353019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov     * Authenticator.
5471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
5526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
5626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
5726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
58e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
59e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
60e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
6171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
62e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
63e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
6426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from changing Wi-Fi
652cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * access points. The default value is <code>false</code>.
66150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect in a managed profile.
6726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
6826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
6926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
70e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
71e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
72e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
7371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi";
74e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
75e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
7626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from installing applications.
7771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
7826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
7926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
8026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
81e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
82e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
83e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
8471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_INSTALL_APPS = "no_install_apps";
85e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
86e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
8726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from uninstalling applications.
8871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
8926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
9026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
9126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
92e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
93e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
94e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
9571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
96e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
9771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
98150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * Specifies if a user is disallowed from turning on location sharing.
9971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
100150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>In a managed profile, location sharing always reflects the primary user's setting, but
101150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * can be overridden and forced off by setting this restriction to true in the managed profile.
10226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
10326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
10426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
1056794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     * @see #setUserRestrictions(Bundle)
1066794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     * @see #getUserRestrictions()
1076794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
10871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_SHARE_LOCATION = "no_share_location";
1096794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
110a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
11126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from enabling the
112a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * "Unknown Sources" setting, that allows installation of apps from unknown sources.
113a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * The default value is <code>false</code>.
11426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
11526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
11626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
117a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
118a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
119a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
120a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
121a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
122a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
12326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring bluetooth.
1241c4c442e4540b16aed7acc345aea26ab101efbf8Nicolas Prevot     * This does <em>not</em> restrict the user from turning bluetooth on or off.
125a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * The default value is <code>false</code>.
126150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect in a managed profile.
12726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
12826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
12926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
130a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
131a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
132a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
133a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
134a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
135a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
13626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from transferring files over
137c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * USB. This can only be set by device owners and profile owners on the primary user.
138c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
13926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
14026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
14126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
142a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
143a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
144a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
145a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
146a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
147b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    /**
14826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring user
149b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * credentials. The default value is <code>false</code>.
15026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
15126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
15226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
153b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #setUserRestrictions(Bundle)
154b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
155b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
156b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
157b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
158b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    /**
159150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * When set on the primary user this specifies if the user can remove other users.
160150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * When set on a secondary user, this specifies if the user can remove itself.
161150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * This restriction has no effect on managed profiles.
162150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * The default value is <code>false</code>.
16326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
16426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
16526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
166b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #setUserRestrictions(Bundle)
167b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
168b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
169b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_REMOVE_USER = "no_remove_user";
170b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
171d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
17226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from enabling or
173d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * accessing debugging features. The default value is <code>false</code>.
17426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
17526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
17626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
177d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
178d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
179d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
180d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
181d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
182d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
18326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring VPN.
184d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * The default value is <code>false</code>.
185298f98fa234f353267ddc9c75d58e8cc542c25f1Nicolas Prevot     * This restriction has an effect in a managed profile only from
1860e3de6cacaffcfeda4d6353be61e2f1f9ed80705Dianne Hackborn     * {@link android.os.Build.VERSION_CODES#M}
18726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
18826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
18926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
190d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
191d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
192d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
193d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_VPN = "no_config_vpn";
194d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
195d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
19626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring Tethering
197c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * & portable hotspots. This can only be set by device owners and profile owners on the
198c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * primary user. The default value is <code>false</code>.
19926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
20026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
20126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
202d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
203d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
204d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
205d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering";
206d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
207d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
208e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * Specifies if a user is disallowed from resetting network settings
209e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * from Settings. This can only be set by device owners and profile owners on the primary user.
210e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * The default value is <code>false</code>.
211e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * <p/>This restriction has no effect on secondary users and managed profiles since only the
212e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * primary user can reset the network settings of the device.
213e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     *
214e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * <p/>Key for user restrictions.
215e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * <p/>Type: Boolean
216e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * @see #setUserRestrictions(Bundle)
217e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * @see #getUserRestrictions()
218e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     */
219e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott    public static final String DISALLOW_NETWORK_RESET = "no_network_reset";
220e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott
221e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott    /**
22226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from factory resetting
223c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * from Settings. This can only be set by device owners and profile owners on the primary user.
224c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
225150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect on secondary users and managed profiles since only the
226150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can factory reset the device.
22726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
22826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
22926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
230d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
231d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
232d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
233d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_FACTORY_RESET = "no_factory_reset";
234d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
235d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
23626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from adding new users and
237c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * profiles. This can only be set by device owners and profile owners on the primary user.
238c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
239150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect on secondary users and managed profiles since only the
240150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can add other users.
24126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
24226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
24326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
244d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
245d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
246d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
247d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_ADD_USER = "no_add_user";
248d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
249d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
25026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from disabling application
251d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * verification. The default value is <code>false</code>.
25226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
25326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
25426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
255d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
256d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
257d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
258d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps";
259d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
260d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
26126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring cell
262c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * broadcasts. This can only be set by device owners and profile owners on the primary user.
263c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
264150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect on secondary users and managed profiles since only the
265150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can configure cell broadcasts.
26626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
26726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
26826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
269d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
270d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
271d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
272d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts";
273d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
274d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
27526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring mobile
276c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * networks. This can only be set by device owners and profile owners on the primary user.
277c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
278150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect on secondary users and managed profiles since only the
279150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can configure mobile networks.
28026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
28126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
28226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
283d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
284d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
285d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
286d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks";
287d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
288d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
28926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from modifying
290c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * applications in Settings or launchers. The following actions will not be allowed when this
291c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * restriction is enabled:
292c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>uninstalling apps</li>
293c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>disabling apps</li>
294c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app caches</li>
295c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app data</li>
296c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>force stopping apps</li>
297c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app defaults</li>
298c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <p>
299c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * The default value is <code>false</code>.
30026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
30126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
30226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
303d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
304d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
305d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
30636fbc8d6453da438a8ab83352ff1bcfcba5f25b5Julia Reynolds    public static final String DISALLOW_APPS_CONTROL = "no_control_apps";
307d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
308394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
30926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from mounting
310c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * physical external media. This can only be set by device owners and profile owners on the
311c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * primary user. The default value is <code>false</code>.
31226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
31326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
31426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
315394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
316394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
317394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
318394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
319394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
320394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
32126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from adjusting microphone
322c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * volume. If set, the microphone will be muted. This can only be set by device owners
323c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * and profile owners on the primary user. The default value is <code>false</code>.
32426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
32526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
32626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
327394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
328394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
329394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
330394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
331394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
332394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
33326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from adjusting the master
334c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * volume. If set, the master volume will be muted. This can only be set by device owners
335c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * and profile owners on the primary user. The default value is <code>false</code>.
33626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
33726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
33826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
339394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
340394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
341394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
342394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume";
343394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
3449f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani    /**
34526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that the user is not allowed to make outgoing
346390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * phone calls. Emergency calls are still permitted.
347390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * The default value is <code>false</code>.
348150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect on managed profiles since call intents are normally
349150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * forwarded to the primary user.
35026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
35126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
35226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
353390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * @see #setUserRestrictions(Bundle)
354390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * @see #getUserRestrictions()
355390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     */
356390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls";
357390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani
358390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    /**
35926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that the user is not allowed to send or receive
360c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * SMS messages. The default value is <code>false</code>.
36126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
36226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
36326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
3649f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * @see #setUserRestrictions(Bundle)
3659f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * @see #getUserRestrictions()
3669f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     */
367390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    public static final String DISALLOW_SMS = "no_sms";
3689f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani
3691c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk    /**
3702cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * Specifies if the user is not allowed to have fun. In some cases, the
3712cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * device owner may wish to prevent the user from experiencing amusement or
3722cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * joy while using the device. The default value is <code>false</code>.
3732cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     *
3742cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * <p/>Key for user restrictions.
3752cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * <p/>Type: Boolean
3762cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * @see #setUserRestrictions(Bundle)
3772cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * @see #getUserRestrictions()
3782cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     */
3792cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey    public static final String DISALLOW_FUN = "no_fun";
3802cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey
3812cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey    /**
38226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that windows besides app windows should not be
3831c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * created. This will block the creation of the following types of windows.
3841c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_TOAST}</li>
3851c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_PHONE}</li>
3861c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li>
3871c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li>
3881c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li>
3891c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li>
3901c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     *
391c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * <p>This can only be set by device owners and profile owners on the primary user.
392c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
39326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
39426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
39526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
3961c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * @see #setUserRestrictions(Bundle)
3971c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * @see #getUserRestrictions()
3981c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     */
3991c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk    public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows";
4001c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk
401f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot    /**
40226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if what is copied in the clipboard of this profile can
403f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be
404f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * pasted in this profile.
405f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * The default value is <code>false</code>.
40626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
40726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
40826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
409f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * @see #setUserRestrictions(Bundle)
410f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * @see #getUserRestrictions()
411f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     */
412f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot    public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste";
413f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot
41426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani    /**
41526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if the user is not allowed to use NFC to beam out data from apps.
41626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * The default value is <code>false</code>.
41726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
41826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
41926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
42026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * @see #setUserRestrictions(Bundle)
42126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * @see #getUserRestrictions()
42226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     */
42326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani    public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam";
42426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani
42553d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse    /**
426f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * Hidden user restriction to disallow access to wallpaper manager APIs. This user restriction
427f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * is always set for managed profiles.
428f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * @hide
429f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * @see #setUserRestrictions(Bundle)
430f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * @see #getUserRestrictions()
431f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     */
432f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz    public static final String DISALLOW_WALLPAPER = "no_wallpaper";
433f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz
434f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz    /**
435bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * Specifies if the user is not allowed to reboot the device into safe boot mode.
436bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * This can only be set by device owners and profile owners on the primary user.
437bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * The default value is <code>false</code>.
438bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     *
439bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * <p/>Key for user restrictions.
440bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * <p/>Type: Boolean
441bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * @see #setUserRestrictions(Bundle)
442bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * @see #getUserRestrictions()
443bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     */
444bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz    public static final String DISALLOW_SAFE_BOOT = "no_safe_boot";
445bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz
446bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz    /**
447b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * Specifies if a user is not allowed to record audio. This restriction is always enabled for
448b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * background users. The default value is <code>false</code>.
449b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     *
450b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * @see #setUserRestrictions(Bundle)
451b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * @see #getUserRestrictions()
452b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * @hide
453b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     */
454b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov    public static final String DISALLOW_RECORD_AUDIO = "no_record_audio";
455b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov
456b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov    /**
457f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot     * Allows apps in the parent profile to handle web links from the managed profile.
458f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot     *
4599edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * This user restriction has an effect only in a managed profile.
4609edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * If set:
4619edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * Intent filters of activities in the parent profile with action
4629edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * {@link android.content.Intent#ACTION_VIEW},
4639edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which
4649edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * define a host can handle intents from the managed profile.
4659edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * The default value is <code>false</code>.
4669edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     *
4679edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * <p/>Key for user restrictions.
4689edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * <p/>Type: Boolean
4699edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * @see #setUserRestrictions(Bundle)
4709edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * @see #getUserRestrictions()
4719edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     */
472f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot    public static final String ALLOW_PARENT_PROFILE_APP_LINKING
473f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot            = "allow_parent_profile_app_linking";
4749edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot
4759edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot    /**
47653d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * Application restriction key that is used to indicate the pending arrival
47753d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * of real restrictions for the app.
47853d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     *
47953d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * <p>
48053d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * Applications that support restrictions should check for the presence of this key.
48153d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * A <code>true</code> value indicates that restrictions may be applied in the near
48253d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * future but are not available yet. It is the responsibility of any
48353d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * management application that sets this flag to update it when the final
48453d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * restrictions are enforced.
48553d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     *
48653d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * <p/>Key for application restrictions.
48753d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * <p/>Type: Boolean
488b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions(
489b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     *      android.content.ComponentName, String, Bundle)
490b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions(
491b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     *      android.content.ComponentName, String)
49253d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     */
49353d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse    public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
49453d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse
495655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
496655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
497655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
498655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2;
499655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
500655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_SUCCESS = -1;
501655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
5027e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /** @hide */
503c0688301de5feea94c8456b3b9b42c41d0045f03Amith Yamasani    public static UserManager get(Context context) {
504c0688301de5feea94c8456b3b9b42c41d0045f03Amith Yamasani        return (UserManager) context.getSystemService(Context.USER_SERVICE);
50527db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    }
506a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
507258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /** @hide */
508258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserManager(Context context, IUserManager service) {
509258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        mService = service;
510258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        mContext = context;
511258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
512258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
513258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
514258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns whether the system supports multiple users.
5151a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @return true if multiple users can be created by user, false if it is a single user device.
516e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @hide
517258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
5184673e7ea8d1f869910a9c0f9c211d4d27ad50b41Jeff Sharkey    public static boolean supportsMultipleUsers() {
5191a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        return getMaxSupportedUsers() > 1
5201a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                && SystemProperties.getBoolean("fw.show_multiuserui",
5211a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));
522258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
523258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
5246794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    /**
5257cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     * @hide
5267cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     * @return Whether the device is running with split system user. It means the system user and
5277cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     * primary user are two separate users. Previously system user and primary user are combined as
5287cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     * a single owner user.  see @link {android.os.UserHandle#USER_OWNER}
5297cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     */
5307cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen    public static boolean isSplitSystemUser() {
5317cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen        return SystemProperties.getBoolean("ro.fw.system_user_split", false);
5327cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen    }
5337cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen
5347cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen    /**
5355760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * Returns the user handle for the user that this process is running under.
536be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     *
5375760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * @return the user handle of this process.
538258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
5396794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
540258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public int getUserHandle() {
54179af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn        return UserHandle.myUserId();
542258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
543258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
544258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
5458832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * Returns the user name of the user making this call.  This call is only
5468832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * available to applications on the system image; it requires the
5478832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * MANAGE_USERS permission.
548258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the user name
549258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
550258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public String getUserName() {
551258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
552258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(getUserHandle()).name;
553258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
554258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user name", re);
555258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return "";
556258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
557258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
558258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
55967a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn    /**
560e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * Used to determine whether the user making this call is subject to
561e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * teleportations.
56267a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     *
563955d8d69ea6caabce1461dc25b339b9bf9dc61a6Dianne Hackborn     * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can
56467a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     * now automatically identify goats using advanced goat recognition technology.</p>
56567a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     *
56667a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     * @return Returns true if the user making this call is a goat.
567e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     */
568e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    public boolean isUserAGoat() {
569988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell        return mContext.getPackageManager()
570988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell                .isPackageAvailable("com.coffeestainstudios.goatsimulator");
571e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    }
572df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
573df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
57470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * Used to check if this process is running under the primary user. The primary user
57570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * is the first human user on a device.
57670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     *
57770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * @return whether this process is running under the primary user.
57870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * @hide
57970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     */
58070f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    public boolean isPrimaryUser() {
58170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        UserInfo user = getUserInfo(UserHandle.myUserId());
58270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        return user != null ? user.isPrimary() : false;
58370f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    }
58470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen
58570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    /**
5865760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * Used to check if this process is running under the system user. The system user
5875760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * is the initial user that is implicitly created on first boot and hosts most of the
5885760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * system services.
5895760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     *
5905760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * @return whether this process is running under the system user.
5915760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     */
5925760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani    public boolean isSystemUser() {
59370f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        return UserHandle.myUserId() == UserHandle.USER_SYSTEM;
5945760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani    }
5952b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen
5965760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani    /**
597462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani     * @hide
598462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani     * Returns whether the caller is running as an admin user. There can be more than one admin
599462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani     * user.
600462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani     */
601462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani    public boolean isAdminUser() {
6022b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen        return isUserAdmin(UserHandle.myUserId());
6032b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen    }
6042b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen
6052b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen    /**
6062b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen     * @hide
6072b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen     * Returns whether the provided user is an admin user. There can be more than one admin
6082b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen     * user.
6092b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen     */
6102b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen    public boolean isUserAdmin(int userId) {
6112b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen        UserInfo user = getUserInfo(userId);
6122b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen        return user != null && user.isAdmin();
613462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani    }
614462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani
615462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani    /**
616e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * Used to check if the user making this call is linked to another user. Linked users may have
61746bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani     * a reduced number of available apps, app restrictions and account restrictions.
618e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * @return whether the user making this call is a linked user
6192555dafce87e60fae28d71913730abf73e40fcd7Amith Yamasani     * @hide
620df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
621e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani    public boolean isLinkedUser() {
622df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
62371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani            return mService.isRestricted();
624df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
62546bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani            Log.w(TAG, "Could not check if user is limited ", re);
626df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            return false;
627df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
628df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
629df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
630258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
6311c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov     * Checks if specified user can have restricted profile.
6321c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov     * @hide
6331c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov     */
6341c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov    public boolean canHaveRestrictedProfile(int userId) {
6351c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov        try {
6361c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov            return mService.canHaveRestrictedProfile(userId);
6371c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov        } catch (RemoteException re) {
6381c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov            Log.w(TAG, "Could not check if user can have restricted profile", re);
6391c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov            return false;
6401c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov        }
6411c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov    }
6421c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov
6431c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov    /**
6441e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * Checks if the calling app is running as a guest user.
6451e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @return whether the caller is a guest user.
6461e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @hide
6471e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     */
6481e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    public boolean isGuestUser() {
6491e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        UserInfo user = getUserInfo(UserHandle.myUserId());
6501e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        return user != null ? user.isGuest() : false;
6511e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    }
6521e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani
6531e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    /**
6540e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * Checks if the calling app is running in a managed profile.
6550e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
6560e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     *
6570e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * @return whether the caller is in a managed profile.
6580e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * @hide
6590e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     */
6600e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    @SystemApi
6610e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    public boolean isManagedProfile() {
6620e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani        UserInfo user = getUserInfo(UserHandle.myUserId());
6630e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani        return user != null ? user.isManagedProfile() : false;
6640e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    }
6650e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani
6660e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    /**
667a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running.  This means that
668a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * the user is in the "started" state, not "stopped" -- it is currently
669a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * allowed to run code through scheduled alarms, receiving broadcasts,
670a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * etc.  A started user may be either the current foreground user or a
671a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * background user; the result here does not distinguish between the two.
672a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
673a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
674a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunning(UserHandle user) {
675a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
676a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return ActivityManagerNative.getDefault().isUserRunning(
677a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn                    user.getIdentifier(), false);
678a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        } catch (RemoteException e) {
679a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return false;
680a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
681a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
682a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
683a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    /**
684a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running <em>or</em> stopping.
685a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * This is like {@link #isUserRunning(UserHandle)}, but will also return
686a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * true if the user had been running but is in the process of being stopped
687a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * (but is not yet fully stopped, and still running some code).
688a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
689a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
690a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunningOrStopping(UserHandle user) {
691a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
692a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return ActivityManagerNative.getDefault().isUserRunning(
693a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn                    user.getIdentifier(), true);
694a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        } catch (RemoteException e) {
695a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return false;
696a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
697a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
698a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
699a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    /**
700258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the UserInfo object describing a specific user.
7011952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
702258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user handle of the user whose information is being requested.
703258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for a specific user.
704258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
705b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
706258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserInfo getUserInfo(int userHandle) {
707258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
708258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(userHandle);
709258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
710258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user info", re);
711258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
712258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
713258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
714258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
71571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
71671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on this user.
71771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
71871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
719e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions() {
720e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        return getUserRestrictions(Process.myUserHandle());
721e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
722e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
72371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
72471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
72571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
72671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
72771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
728e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions(UserHandle userHandle) {
729e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        try {
730e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            return mService.getUserRestrictions(userHandle.getIdentifier());
731e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        } catch (RemoteException re) {
732e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            Log.w(TAG, "Could not get user restrictions", re);
733e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            return Bundle.EMPTY;
734e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        }
735e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
736e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
73771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
73871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets all the user-wide restrictions for this user.
739be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
74071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param restrictions the Bundle containing all the restrictions.
7413d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
7423d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
7433d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
7443d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
74571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
7463d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
747e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions) {
748e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        setUserRestrictions(restrictions, Process.myUserHandle());
749e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
750e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
75171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
75271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets all the user-wide restrictions for the specified user.
753be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
75471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param restrictions the Bundle containing all the restrictions.
75571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the UserHandle of the user for whom to set the restrictions.
7563d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
7573d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
7583d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
7593d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
76071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
7613d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
762e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
763e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        try {
764e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            mService.setUserRestrictions(restrictions, userHandle.getIdentifier());
765e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        } catch (RemoteException re) {
766e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            Log.w(TAG, "Could not set user restrictions", re);
767e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        }
768e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
769e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
77071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
77171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction.
772be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
77371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
77471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
7753d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
7763d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
7773d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
7783d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
77971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
7803d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
78171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public void setUserRestriction(String key, boolean value) {
78271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        Bundle bundle = getUserRestrictions();
78371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        bundle.putBoolean(key, value);
78471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        setUserRestrictions(bundle);
78571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    }
78671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani
78771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
78871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @hide
78971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction on a specific user.
790be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
79171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
79271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
79371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the user whose restriction is to be changed.
7943d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
7953d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
7963d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
7973d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
79871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
7993d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
8006794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
801b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov        try {
802b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov            mService.setUserRestriction(key, value, userHandle.getIdentifier());
803b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov        } catch (RemoteException re) {
804b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov            Log.w(TAG, "Could not set user restriction", re);
805b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov        }
8066794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    }
8076794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
808258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
809a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Returns whether the current user has been disallowed from performing certain actions
810a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * or setting certain settings.
8112b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     *
8122b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     * @param restrictionKey The string key representing the restriction.
8132b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     * @return {@code true} if the current user has the given restriction, {@code false} otherwise.
814a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
815a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public boolean hasUserRestriction(String restrictionKey) {
816b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie        return hasUserRestriction(restrictionKey, Process.myUserHandle());
817b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    }
818b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie
819b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    /**
820b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @hide
821b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * Returns whether the given user has been disallowed from performing certain actions
822b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * or setting certain settings.
823b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param restrictionKey the string key representing the restriction
824b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
825b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     */
826b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
8278cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        try {
8288cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani            return mService.hasUserRestriction(restrictionKey,
8298cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani                    userHandle.getIdentifier());
8308cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        } catch (RemoteException re) {
8318cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani            Log.w(TAG, "Could not check user restrictions", re);
8328cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani            return false;
8338cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        }
834a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    }
835a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
836a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
83733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the serial number for a user.  This is a device-unique
838b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * number assigned to that user; if the user is deleted and then a new
839b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * user created, the new users will not be given the same serial number.
84033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param user The user whose serial number is to be retrieved.
841b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * @return The serial number of the given user; returns -1 if the
842b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * given UserHandle does not exist.
84333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getUserForSerialNumber(long)
84433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
84533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public long getSerialNumberForUser(UserHandle user) {
84633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return getUserSerialNumber(user.getIdentifier());
84733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
84833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
84933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
85033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the user associated with a serial number previously
85133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * returned by {@link #getSerialNumberForUser(UserHandle)}.
85233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param serialNumber The serial number of the user that is being
85333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * retrieved.
85433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @return Return the user associated with the serial number, or null
85533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * if there is not one.
85633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getSerialNumberForUser(UserHandle)
85733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
85833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public UserHandle getUserForSerialNumber(long serialNumber) {
859ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov        int ident = getUserHandle((int) serialNumber);
86033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return ident >= 0 ? new UserHandle(ident) : null;
86133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
86233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
86333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
864cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen     * Creates a user with the specified name and options. For non-admin users, default user
865cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen     * restrictions are going to be applied.
8661952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
867258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
868258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the user's name
869258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param flags flags that identify the type of user and other properties.
870258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @see UserInfo
871258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
872258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for the created user, or null if the user could not be created.
873258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
874258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
875258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserInfo createUser(String name, int flags) {
876cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen        UserInfo user = null;
877258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
878cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen            user = mService.createUser(name, flags);
879cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen            if (user != null && !user.isAdmin()) {
880cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen                Bundle userRestrictions = mService.getUserRestrictions(user.id);
881cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen                addDefaultUserRestrictions(userRestrictions);
882cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen                mService.setUserRestrictions(userRestrictions, user.id);
883cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen            }
884258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
885258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not create a user", re);
886258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
887cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen        return user;
888258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
889258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
890258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
8911e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * Creates a guest user and configures it.
8921e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @param context an application context
8931e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @param name the name to set for the user
8941e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @hide
8951e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     */
8961e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    public UserInfo createGuest(Context context, String name) {
8971e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        UserInfo guest = createUser(name, UserInfo.FLAG_GUEST);
8981e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        if (guest != null) {
8991e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani            Settings.Secure.putStringForUser(context.getContentResolver(),
9001e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani                    Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
901bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani            try {
9028616af1a4dd1877996fbd5bb0179659f4f123573Amith Yamasani                Bundle guestRestrictions = mService.getDefaultGuestRestrictions();
9038616af1a4dd1877996fbd5bb0179659f4f123573Amith Yamasani                guestRestrictions.putBoolean(DISALLOW_SMS, true);
90429ce85bab94a2d0dc98d9075ae86c8a282367117Amith Yamasani                guestRestrictions.putBoolean(DISALLOW_INSTALL_UNKNOWN_SOURCES, true);
9058616af1a4dd1877996fbd5bb0179659f4f123573Amith Yamasani                mService.setUserRestrictions(guestRestrictions, guest.id);
906bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani            } catch (RemoteException re) {
907bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani                Log.w(TAG, "Could not update guest restrictions");
908bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani            }
9091e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        }
9101e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        return guest;
9111e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    }
9121e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani
913aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani    private static void addDefaultUserRestrictions(Bundle restrictions) {
914aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani        restrictions.putBoolean(DISALLOW_OUTGOING_CALLS, true);
915aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani        restrictions.putBoolean(DISALLOW_SMS, true);
916aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani    }
917aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani
918aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani    /**
9192a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Creates a user with the specified name and options as a profile of another user.
920a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
921a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     *
922a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @param name the user's name
923a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @param flags flags that identify the type of user and other properties.
924a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @see UserInfo
9252a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @param userHandle new user will be a profile of this use.
926a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     *
927a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @return the UserInfo object for the created user, or null if the user could not be created.
928a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @hide
929a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     */
9302a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy    public UserInfo createProfileForUser(String name, int flags, int userHandle) {
931a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        try {
9322a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy            return mService.createProfileForUser(name, flags, userHandle);
933a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        } catch (RemoteException re) {
934a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            Log.w(TAG, "Could not create a user", re);
935a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            return null;
936a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        }
937a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    }
938a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy
939a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    /**
94002cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov     * Creates a restricted profile with the specified name. This method also sets necessary
94102cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov     * restrictions and adds shared accounts.
94206a484adb93c6c969321147b07112684383305f6Fyodor Kupolov     *
94306a484adb93c6c969321147b07112684383305f6Fyodor Kupolov     * @param name profile's name
94406a484adb93c6c969321147b07112684383305f6Fyodor Kupolov     * @return UserInfo object for the created user, or null if the user could not be created.
94506a484adb93c6c969321147b07112684383305f6Fyodor Kupolov     * @hide
94606a484adb93c6c969321147b07112684383305f6Fyodor Kupolov     */
94706a484adb93c6c969321147b07112684383305f6Fyodor Kupolov    public UserInfo createRestrictedProfile(String name) {
94806a484adb93c6c969321147b07112684383305f6Fyodor Kupolov        try {
94902cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov            UserHandle parentUserHandle = Process.myUserHandle();
95002cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov            UserInfo user = mService.createRestrictedProfile(name,
95102cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov                    parentUserHandle.getIdentifier());
95202cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov            if (user != null) {
95302cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov                AccountManager.get(mContext).addSharedAccountsFromParentUser(parentUserHandle,
95402cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov                        UserHandle.of(user.id));
95506a484adb93c6c969321147b07112684383305f6Fyodor Kupolov            }
95602cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov            return user;
95706a484adb93c6c969321147b07112684383305f6Fyodor Kupolov        } catch (RemoteException e) {
95806a484adb93c6c969321147b07112684383305f6Fyodor Kupolov            Log.w(TAG, "Could not create a restricted profile", e);
95906a484adb93c6c969321147b07112684383305f6Fyodor Kupolov        }
96006a484adb93c6c969321147b07112684383305f6Fyodor Kupolov        return null;
96106a484adb93c6c969321147b07112684383305f6Fyodor Kupolov    }
96206a484adb93c6c969321147b07112684383305f6Fyodor Kupolov
96306a484adb93c6c969321147b07112684383305f6Fyodor Kupolov    /**
9641df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @hide
9651df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * Marks the guest user for deletion to allow a new guest to be created before deleting
9661df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * the current user who is a guest.
9671df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @param userHandle
9681df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @return
9691df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     */
9701df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    public boolean markGuestForDeletion(int userHandle) {
9711df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        try {
9721df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani            return mService.markGuestForDeletion(userHandle);
9731df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        } catch (RemoteException re) {
9741df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani            Log.w(TAG, "Could not mark guest for deletion", re);
9751df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani            return false;
9761df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        }
9771df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    }
9781df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani
9791df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    /**
980df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Sets the user as enabled, if such an user exists.
981df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
982df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Note that the default is true, it's only that managed profiles might not be enabled.
983df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     *
984df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * @param userHandle the id of the profile to enable
985df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * @hide
986df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     */
987df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    public void setUserEnabled(int userHandle) {
988df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        try {
989df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina            mService.setUserEnabled(userHandle);
990df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        } catch (RemoteException e) {
991df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina            Log.w(TAG, "Could not enable the profile", e);
992df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        }
993df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    }
994df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina
995df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    /**
996b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * Return the number of users currently created on the device.
997b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
998b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    public int getUserCount() {
999b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        List<UserInfo> users = getUsers();
1000b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        return users != null ? users.size() : 1;
1001b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    }
1002b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn
1003b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    /**
1004258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns information for all users on this device.
10051952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1006258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the list of users that were created.
1007258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1008258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1009258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public List<UserInfo> getUsers() {
1010258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1011920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(false);
1012920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        } catch (RemoteException re) {
1013920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            Log.w(TAG, "Could not get user list", re);
1014920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return null;
1015920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        }
1016920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    }
1017920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani
1018920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    /**
101970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * Returns information for Primary user.
102070f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
102170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     *
102270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * @return the Primary user, null if not found.
102370f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * @hide
102470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     */
10257cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen    public @Nullable UserInfo getPrimaryUser() {
102670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        try {
102770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen            return mService.getPrimaryUser();
102870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        } catch (RemoteException re) {
102970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen            Log.w(TAG, "Could not get Primary user", re);
103070f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen            return null;
103170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        }
103270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    }
103370f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen
103470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    /**
103595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS
103695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * permission.
103795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     *
103895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * @return true if more users can be added, false if limit has been reached.
103995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * @hide
104095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     */
104195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    public boolean canAddMoreUsers() {
104295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        final List<UserInfo> users = getUsers(true);
104395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        final int totalUserCount = users.size();
104495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        int aliveUserCount = 0;
104595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        for (int i = 0; i < totalUserCount; i++) {
104695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            UserInfo user = users.get(i);
104795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            if (!user.isGuest()) {
104895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani                aliveUserCount++;
104995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            }
105095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        }
105195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        return aliveUserCount < getMaxSupportedUsers();
105295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    }
105395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani
105495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    /**
105572434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS
105672434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * permission.
105772434b7088591828082dd952496d523ef3622de2Nicolas Prevot     *
105872434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * @return true if more managed profiles can be added, false if limit has been reached.
105972434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * @hide
106072434b7088591828082dd952496d523ef3622de2Nicolas Prevot     */
1061b818681dcae157412b897587ff856cd0c531c3f4Nicolas Prevot    public boolean canAddMoreManagedProfiles(int userId) {
106272434b7088591828082dd952496d523ef3622de2Nicolas Prevot        try {
1063b818681dcae157412b897587ff856cd0c531c3f4Nicolas Prevot            return mService.canAddMoreManagedProfiles(userId);
106472434b7088591828082dd952496d523ef3622de2Nicolas Prevot        } catch (RemoteException re) {
106572434b7088591828082dd952496d523ef3622de2Nicolas Prevot            Log.w(TAG, "Could not check if we can add more managed profiles", re);
106672434b7088591828082dd952496d523ef3622de2Nicolas Prevot            return false;
106772434b7088591828082dd952496d523ef3622de2Nicolas Prevot        }
106872434b7088591828082dd952496d523ef3622de2Nicolas Prevot    }
106972434b7088591828082dd952496d523ef3622de2Nicolas Prevot
107072434b7088591828082dd952496d523ef3622de2Nicolas Prevot    /**
10712a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Returns list of the profiles of userHandle including
10722a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * userHandle itself.
10734f7e2e334e4ca5f1a67baf4bdd40cd080b954161Amith Yamasani     * Note that this returns both enabled and not enabled profiles. See
10747f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * {@link #getEnabledProfiles(int)} if you need only the enabled ones.
10754f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *
10762a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
10772a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @param userHandle profiles of this user will be returned.
10782a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @return the list of profiles.
10792a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @hide
10802a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     */
10812a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy    public List<UserInfo> getProfiles(int userHandle) {
1082a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        try {
1083385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            return mService.getProfiles(userHandle, false /* enabledOnly */);
1084a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        } catch (RemoteException re) {
1085a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            Log.w(TAG, "Could not get user list", re);
1086a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            return null;
1087a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        }
1088a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    }
1089a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy
1090a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    /**
1091fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1092fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     * @param userId one of the two user ids to check.
1093fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     * @param otherUserId one of the two user ids to check.
1094fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     * @return true if the two user ids are in the same profile group.
1095fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     * @hide
1096fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     */
1097fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen    public boolean isSameProfileGroup(int userId, int otherUserId) {
1098fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen        try {
1099fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen            return mService.isSameProfileGroup(userId, otherUserId);
1100fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen        } catch (RemoteException re) {
1101fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen            Log.w(TAG, "Could not get user list", re);
1102fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen            return false;
1103fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen        }
1104fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen    }
1105fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen
1106fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen    /**
11077f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * Returns list of the profiles of userHandle including
11087f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * userHandle itself.
11097f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * Note that this returns only enabled.
11107f75da2405cd910854448bb3801f776e036f926aRuben Brunk     *
11117f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
11127f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * @param userHandle profiles of this user will be returned.
11137f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * @return the list of profiles.
11147f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * @hide
11157f75da2405cd910854448bb3801f776e036f926aRuben Brunk     */
11167f75da2405cd910854448bb3801f776e036f926aRuben Brunk    public List<UserInfo> getEnabledProfiles(int userHandle) {
11177f75da2405cd910854448bb3801f776e036f926aRuben Brunk        try {
11187f75da2405cd910854448bb3801f776e036f926aRuben Brunk            return mService.getProfiles(userHandle, true /* enabledOnly */);
11197f75da2405cd910854448bb3801f776e036f926aRuben Brunk        } catch (RemoteException re) {
11207f75da2405cd910854448bb3801f776e036f926aRuben Brunk            Log.w(TAG, "Could not get user list", re);
11217f75da2405cd910854448bb3801f776e036f926aRuben Brunk            return null;
11227f75da2405cd910854448bb3801f776e036f926aRuben Brunk        }
11237f75da2405cd910854448bb3801f776e036f926aRuben Brunk    }
11247f75da2405cd910854448bb3801f776e036f926aRuben Brunk
11257f75da2405cd910854448bb3801f776e036f926aRuben Brunk    /**
1126be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns a list of UserHandles for profiles associated with the user that the calling process
1127be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * is running on, including the user itself.
11284f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *
11294f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * @return A non-empty list of UserHandles associated with the calling user.
11304f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     */
11314f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    public List<UserHandle> getUserProfiles() {
11324f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        ArrayList<UserHandle> profiles = new ArrayList<UserHandle>();
11332b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen        List<UserInfo> users;
1134385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        try {
1135f2e7b3f56ae0ea9f49b5c50413b9be71d5249d6dAlexandra Gherghina            users = mService.getProfiles(UserHandle.myUserId(), true /* enabledOnly */);
1136385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        } catch (RemoteException re) {
1137385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            Log.w(TAG, "Could not get user list", re);
1138385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            return null;
1139385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        }
11404f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        for (UserInfo info : users) {
11414f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            UserHandle userHandle = new UserHandle(info.id);
11424f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            profiles.add(userHandle);
11434f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        }
11444f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        return profiles;
11454f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
11464f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
11477dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani    /**
1148c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     * Returns the device credential owner id of the profile from
1149c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     * which this method is called, or userHandle if called from a user that
1150c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     * is not a profile.
1151c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     *
1152c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     * @hide
1153c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     */
1154c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales    public int getCredentialOwnerProfile(int userHandle) {
1155c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales        try {
1156c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales            return mService.getCredentialOwnerProfile(userHandle);
1157c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales        } catch (RemoteException re) {
1158c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales            Log.w(TAG, "Could not get credential owner", re);
1159c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales            return -1;
1160c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales        }
1161c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales    }
1162c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales
1163c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales    /**
1164be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns the parent of the profile which this method is called from
1165be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * or null if called from a user that is not a profile.
1166be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     *
1167be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * @hide
1168be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     */
1169be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    public UserInfo getProfileParent(int userHandle) {
1170be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        try {
1171be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            return mService.getProfileParent(userHandle);
1172be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        } catch (RemoteException re) {
1173be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            Log.w(TAG, "Could not get profile parent", re);
1174be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            return null;
1175be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        }
1176be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    }
1177be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel
1178be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    /**
11797dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * If the target user is a managed profile of the calling user or the caller
11807dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * is itself a managed profile, then this returns a badged copy of the given
1181c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * icon to be able to distinguish it from the original icon. For badging an
1182c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * arbitrary drawable use {@link #getBadgedDrawableForUser(
1183c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
1184c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * <p>
1185c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the original drawable is a BitmapDrawable and the backing bitmap is
1186c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
1187c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is performed in place and the original drawable is returned.
1188c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * </p>
1189c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *
1190c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param icon The icon to badge.
1191c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param user The target user.
1192c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @return A drawable that combines the original icon and a badge as
1193c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         determined by the system.
1194c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
1195c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     */
1196c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) {
1197c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedIcon(icon, user);
1198c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    }
1199c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav
1200c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    /**
1201c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the target user is a managed profile of the calling user or the caller
1202c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is itself a managed profile, then this returns a badged copy of the given
1203c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * drawable allowing the user to distinguish it from the original drawable.
1204c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * The caller can specify the location in the bounds of the drawable to be
1205c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * badged where the badge should be applied as well as the density of the
1206c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * badge to be used.
1207c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * <p>
1208c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the original drawable is a BitmapDrawable and the backing bitmap is
1209c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
1210c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is performed in place and the original drawable is returned.
1211c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * </p>
1212c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *
1213c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgedDrawable The drawable to badge.
1214c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param user The target user.
1215c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgeLocation Where in the bounds of the badged drawable to place
1216c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         the badge. If not provided, the badge is applied on top of the entire
1217c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         drawable being badged.
1218c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgeDensity The optional desired density for the badge as per
1219c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         {@link android.util.DisplayMetrics#densityDpi}. If not provided,
1220c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         the density of the display is used.
1221c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @return A drawable that combines the original drawable and a badge as
1222c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         determined by the system.
1223c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
1224c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     */
1225c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user,
1226c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            Rect badgeLocation, int badgeDensity) {
1227c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user,
1228c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav                badgeLocation, badgeDensity);
12294f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
12304f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
1231701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    /**
1232701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * If the target user is a managed profile of the calling user or the caller
1233f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * is itself a managed profile, then this returns a copy of the label with
1234f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * badging for accessibility services like talkback. E.g. passing in "Email"
1235f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * and it might return "Work Email" for Email in the work profile.
1236f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     *
1237f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @param label The label to change.
1238f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @param user The target user.
1239f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @return A label that combines the original label and a badge as
1240f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     *         determined by the system.
1241c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
1242f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     */
1243237aecd18d0edf56c038761f570758c310c9e6dfKenny Guy    public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) {
1244c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedLabel(label, user);
12454f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
12464f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
12474f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    /**
12484f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * Returns information for all users on this device. Requires
12494f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * {@link android.Manifest.permission#MANAGE_USERS} permission.
1250394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     *
12514f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * @param excludeDying specify if the list should exclude users being
12524f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *            removed.
1253920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @return the list of users that were created.
1254920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @hide
1255920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     */
1256920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    public List<UserInfo> getUsers(boolean excludeDying) {
1257920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        try {
1258920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(excludeDying);
1259258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1260258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user list", re);
1261258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
1262258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1263258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1264258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1265258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
1266258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Removes a user and all associated data.
12671952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1268258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the integer handle of the user, where 0 is the primary user.
1269258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1270258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1271258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public boolean removeUser(int userHandle) {
1272258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1273258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.removeUser(userHandle);
1274258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1275258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not remove user ", re);
1276258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return false;
1277258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1278258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1279258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1280258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
1281258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Updates the user's name.
12821952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1283258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
1284258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user's integer handle
1285258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the new name for the user
1286258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1287258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1288258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public void setUserName(int userHandle, String name) {
1289258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1290258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            mService.setUserName(userHandle, name);
1291258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1292258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not set the user name ", re);
1293258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1294258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1295258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1296258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
1297e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * Sets the user's photo.
1298258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user for whom to change the photo.
1299e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @param icon the bitmap to set as the photo.
1300258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1301258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1302e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani    public void setUserIcon(int userHandle, Bitmap icon) {
1303258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1304e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani            mService.setUserIcon(userHandle, icon);
1305258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1306258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not set the user icon ", re);
1307258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1308258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1309258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1310258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
13113b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * Returns a file descriptor for the user's photo. PNG data can be read from this file.
13123b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @param userHandle the user whose photo we want to read.
1313e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
131464d4dca63f65e4c7d4a829c85ff6670bdd34e2ebAlexandra Gherghina     * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
13153b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @hide
13163b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     */
1317e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani    public Bitmap getUserIcon(int userHandle) {
13183b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        try {
13191bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos            ParcelFileDescriptor fd = mService.getUserIcon(userHandle);
13201bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos            if (fd != null) {
13211bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                try {
13221bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
13231bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                } finally {
13241bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    try {
13251bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                        fd.close();
13261bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    } catch (IOException e) {
13271bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    }
13281bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                }
13291bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos            }
13303b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        } catch (RemoteException re) {
1331e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani            Log.w(TAG, "Could not get the user icon ", re);
13323b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        }
13331bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos        return null;
13343b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    }
13353b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani
13363b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    /**
1337258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the maximum number of users that can be created on this device. A return value
1338258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * of 1 means that it is a single user device.
1339258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1340a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @return a value greater than or equal to 1
1341258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
134227bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey    public static int getMaxSupportedUsers() {
1343ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        // Don't allow multiple users on certain builds
1344ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        if (android.os.Build.ID.startsWith("JVP")) return 1;
1345409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn        // Svelte devices don't get multi-user.
1346409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn        if (ActivityManager.isLowRamDeviceStatic()) return 1;
134727bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey        return SystemProperties.getInt("fw.max_users",
134827bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey                Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
1349258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
13502a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
13512a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
1352cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov     * Returns true if the user switcher should be shown, this will be if device supports multi-user
1353cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov     * and there are at least 2 users available that are not managed profiles.
13541a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @hide
13551a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @return true if user switcher should be shown.
13561a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     */
13571a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    public boolean isUserSwitcherEnabled() {
1358cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov        if (!supportsMultipleUsers()) {
1359cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov            return false;
1360cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov        }
13611a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        List<UserInfo> users = getUsers(true);
13621a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        if (users == null) {
13631a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy           return false;
13641a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        }
13651a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        int switchableUserCount = 0;
13661a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        for (UserInfo user : users) {
13677cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen            if (user.supportsSwitchToByUser()) {
13681a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                ++switchableUserCount;
13691a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy            }
13701a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        }
1371cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov        final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class)
1372cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov                .getGuestUserDisabled(null);
1373a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani        return switchableUserCount > 1 || guestEnabled;
13741a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    }
13751a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy
13761a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    /**
13772a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a serial number on this device for a given userHandle. User handles can be recycled
13782a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * when deleting and creating users, but serial numbers are not reused until the device is wiped.
13792a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userHandle
13802a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return a serial number associated with that user, or -1 if the userHandle is not valid.
13812a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
13822a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
13832a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    public int getUserSerialNumber(int userHandle) {
13842a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
13852a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserSerialNumber(userHandle);
13862a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
13872a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            Log.w(TAG, "Could not get serial number for user " + userHandle);
13882a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
13892a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        return -1;
13902a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
13912a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
13922a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
13932a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a userHandle on this device for a given user serial number. User handles can be
13942a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * recycled when deleting and creating users, but serial numbers are not reused until the device
13952a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is wiped.
13962a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userSerialNumber
13972a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return the userHandle associated with that user serial number, or -1 if the serial number
13982a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is not valid.
13992a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
14002a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
14012a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    public int getUserHandle(int userSerialNumber) {
14022a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
14032a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserHandle(userSerialNumber);
14042a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
14052a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            Log.w(TAG, "Could not get userHandle for user " + userSerialNumber);
14062a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
14072a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        return -1;
14082a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
14096794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
14107e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /**
14117e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * Returns a Bundle containing any saved application restrictions for this user, for the
14127e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * given package name. Only an application with this package name can call this method.
14137e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * @param packageName the package name of the calling application
14147e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * @return a Bundle with the restrictions as key/value pairs, or null if there are no
14157e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * saved restrictions. The values can be of type Boolean, String or String[], depending
14167e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * on the restriction type, as defined by the application.
14177e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     */
14187e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName) {
14197e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        try {
14207e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictions(packageName);
14217e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        } catch (RemoteException re) {
14227e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            Log.w(TAG, "Could not get application restrictions for package " + packageName);
14237e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        }
14247e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        return null;
14257e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    }
1426df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
1427df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
1428df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
1429df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
14307e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
1431df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
14327e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
1433df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
1434df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier());
1435df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
1436df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        return null;
1437df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
1438df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
1439df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
1440df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
1441df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
14427e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public void setApplicationRestrictions(String packageName, Bundle restrictions,
1443df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            UserHandle user) {
1444df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
14457e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
1446df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
1447df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier());
1448df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
1449df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
1450655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
1451655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
1452d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * Sets a new challenge PIN for restrictions. This is only for use by pre-installed
1453d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * apps and requires the MANAGE_USERS permission.
1454d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @param newPin the PIN to use for challenge dialogs.
1455d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @return Returns true if the challenge PIN was set successfully.
1456ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov     * @deprecated The restrictions PIN functionality is no longer provided by the system.
1457ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov     * This method is preserved for backwards compatibility reasons and always returns false.
1458655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
1459d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public boolean setRestrictionsChallenge(String newPin) {
1460655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return false;
1461655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
14621a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani
14631a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    /** @hide */
14641a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    public void removeRestrictions() {
14651a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        try {
14661a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani            mService.removeRestrictions();
14671a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        } catch (RemoteException re) {
14681a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani            Log.w(TAG, "Could not change restrictions pin");
14691a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        }
14701a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    }
1471e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani
1472e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    /**
1473e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * @hide
1474e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * Set restrictions that should apply to any future guest user that's created.
1475e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     */
1476e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    public void setDefaultGuestRestrictions(Bundle restrictions) {
1477e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        try {
1478e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            mService.setDefaultGuestRestrictions(restrictions);
1479e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        } catch (RemoteException re) {
1480e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            Log.w(TAG, "Could not set guest restrictions");
1481e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        }
1482e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    }
1483e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani
1484e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    /**
1485e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * @hide
1486e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * Gets the default guest restrictions.
1487e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     */
1488e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    public Bundle getDefaultGuestRestrictions() {
1489e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        try {
1490e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            return mService.getDefaultGuestRestrictions();
1491e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        } catch (RemoteException re) {
1492e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            Log.w(TAG, "Could not set guest restrictions");
1493e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        }
1494e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        return new Bundle();
1495e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    }
1496ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov
1497ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov    /**
1498ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     * Returns creation time of the user or of a managed profile associated with the calling user.
1499ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     * @param userHandle user handle of the user or a managed profile associated with the
1500ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     *                   calling user.
1501ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     * @return creation time in milliseconds since Epoch time.
1502ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     */
1503385de624aa990266ffbaf70711ac8a330569429eFyodor Kupolov    public long getUserCreationTime(UserHandle userHandle) {
1504ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov        try {
1505385de624aa990266ffbaf70711ac8a330569429eFyodor Kupolov            return mService.getUserCreationTime(userHandle.getIdentifier());
1506ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov        } catch (RemoteException re) {
1507ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov            Log.w(TAG, "Could not get user creation time", re);
1508ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov            return 0;
1509ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov        }
1510ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov    }
1511258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani}
1512