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 */ 168a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey 17258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipackage android.os; 18258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 19b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chenimport android.Manifest; 2002cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolovimport android.accounts.AccountManager; 21e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Banimport android.annotation.IntDef; 22ada8deb43649aed879ceba28daee4af69ae0cc8dAdam Lesinskiimport android.annotation.NonNull; 237cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chenimport android.annotation.Nullable; 24b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chenimport android.annotation.RequiresPermission; 250e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasaniimport android.annotation.SystemApi; 26d86b8fea43ebb6e5c31691b44d8ceb0d8d3c9072Jeff Sharkeyimport android.annotation.SystemService; 27e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onukiimport android.annotation.TestApi; 288588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkeyimport android.annotation.UserIdInt; 294e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolovimport android.annotation.WorkerThread; 3037ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasaniimport android.app.Activity; 31409297da182267465adbc21cfb75a23e8d678117Dianne Hackbornimport android.app.ActivityManager; 32cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolovimport android.app.admin.DevicePolicyManager; 33068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onukiimport android.content.ComponentName; 34258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.Context; 3512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasaniimport android.content.Intent; 368bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talaveraimport android.content.IntentFilter; 37f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franzimport android.content.IntentSender; 38258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.pm.UserInfo; 3927bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkeyimport android.content.res.Resources; 406794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport android.graphics.Bitmap; 411bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roosimport android.graphics.BitmapFactory; 424f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.Rect; 434f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.drawable.Drawable; 441e9c21871e81642669079cd290ef47818a3165bdAmith Yamasaniimport android.provider.Settings; 45523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolovimport android.telephony.TelephonyManager; 461c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monkimport android.view.WindowManager.LayoutParams; 47258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 486794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport com.android.internal.R; 49aa67f684ff43c81e3280c846245ec6ebe907787eJohn Reckimport com.android.internal.os.RoSystemProperties; 506794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 511bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roosimport java.io.IOException; 52e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Banimport java.lang.annotation.Retention; 53e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Banimport java.lang.annotation.RetentionPolicy; 544f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport java.util.ArrayList; 55258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport java.util.List; 56258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 57258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/** 580696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * Manages users and user details on a multi-user system. There are two major categories of 590696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * users: fully customizable users with their own login, and managed profiles that share a workspace 600696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * with a related user. 610696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * <p> 620696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * Users are different from accounts, which are managed by 630696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * {@link AccountManager}. Each user can have their own set of accounts. 640696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * <p> 650696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * See {@link DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE} for more on managed profiles. 66258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 67d86b8fea43ebb6e5c31691b44d8ceb0d8d3c9072Jeff Sharkey@SystemService(Context.USER_SERVICE) 68258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipublic class UserManager { 69258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 704f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov private static final String TAG = "UserManager"; 71258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani private final IUserManager mService; 72258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani private final Context mContext; 73258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 74d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki private Boolean mIsManagedProfileCached; 75d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki 76e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 77e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * @hide 78e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * No user restriction. 79e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban */ 80e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban @SystemApi 81e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban public static final int RESTRICTION_NOT_SET = 0x0; 82e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban 83e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban /** 84e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * @hide 85e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * User restriction set by system/user. 86e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban */ 87e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban @SystemApi 88e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban public static final int RESTRICTION_SOURCE_SYSTEM = 0x1; 89e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban 90e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban /** 91e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * @hide 92e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * User restriction set by a device owner. 93e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban */ 94e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban @SystemApi 95e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban public static final int RESTRICTION_SOURCE_DEVICE_OWNER = 0x2; 96e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban 97e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban /** 98e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * @hide 99e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * User restriction set by a profile owner. 100e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban */ 101e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban @SystemApi 102e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban public static final int RESTRICTION_SOURCE_PROFILE_OWNER = 0x4; 103e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban 104e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban /** @hide */ 105e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban @Retention(RetentionPolicy.SOURCE) 106e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban @IntDef(flag=true, value={RESTRICTION_NOT_SET, RESTRICTION_SOURCE_SYSTEM, 107e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban RESTRICTION_SOURCE_DEVICE_OWNER, RESTRICTION_SOURCE_PROFILE_OWNER}) 108e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban @SystemApi 109e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban public @interface UserRestrictionSource {} 110e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban 111e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban /** 11253019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov * Specifies if a user is disallowed from adding and removing accounts, unless they are 11353019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov * {@link android.accounts.AccountManager#addAccountExplicitly programmatically} added by 11453019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov * Authenticator. 11571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 11626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 117b6c0ce4ac915cd5ab9a308cb0a4861c4e2cd7dfbBenjamin Franz * <p>From {@link android.os.Build.VERSION_CODES#N} a profile or device owner app can still 118b6c0ce4ac915cd5ab9a308cb0a4861c4e2cd7dfbBenjamin Franz * use {@link android.accounts.AccountManager} APIs to add or remove accounts when account 119b6c0ce4ac915cd5ab9a308cb0a4861c4e2cd7dfbBenjamin Franz * management is disallowed. 120b6c0ce4ac915cd5ab9a308cb0a4861c4e2cd7dfbBenjamin Franz * 1210ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1220ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 123068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 124068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 125e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 126e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 12771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts"; 128e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 129e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 13026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from changing Wi-Fi 1312cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds * access points. The default value is <code>false</code>. 1320ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect in a managed profile. 13326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 1340ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1350ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 136068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 137068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 138e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 139e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 14071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi"; 141e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 142e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 14326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from installing applications. 14471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 14526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 1460ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1470ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 148068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 149068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 150e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 151e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 15271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_INSTALL_APPS = "no_install_apps"; 153e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 154e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 15526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from uninstalling applications. 15671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 15726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 1580ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1590ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 160068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 161068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 162e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 163e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 16471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps"; 165e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 16671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 167150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * Specifies if a user is disallowed from turning on location sharing. 16871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 1690ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>In a managed profile, location sharing always reflects the primary user's setting, but 170150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * can be overridden and forced off by setting this restriction to true in the managed profile. 17126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 1720ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1730ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 174068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 175068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 1766794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall * @see #getUserRestrictions() 1776794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall */ 17871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_SHARE_LOCATION = "no_share_location"; 1796794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 180a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 18126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from enabling the 182a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * "Unknown Sources" setting, that allows installation of apps from unknown sources. 183a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * The default value is <code>false</code>. 18426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 1850ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1860ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 187068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 188068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 189a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #getUserRestrictions() 190a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 191a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources"; 192a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 193a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 19426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring bluetooth. 1951c4c442e4540b16aed7acc345aea26ab101efbf8Nicolas Prevot * This does <em>not</em> restrict the user from turning bluetooth on or off. 196a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * The default value is <code>false</code>. 19763d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova * <p>This restriction doesn't prevent the user from using bluetooth. For disallowing usage of 19863d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova * bluetooth completely on the device, use {@link #DISALLOW_BLUETOOTH}. 1990ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect in a managed profile. 20026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 2010ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 2020ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 203068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 204068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 205a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #getUserRestrictions() 206a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 207a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth"; 208a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 209a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 21063d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova * Specifies if bluetooth is disallowed on the device. 21163d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova * 21263d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova * <p> This restriction can only be set by the device owner and the profile owner on the 21363d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova * primary user and it applies globally - i.e. it disables bluetooth on the entire device. 21463d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova * <p>The default value is <code>false</code>. 21563d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova * <p>Key for user restrictions. 21663d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova * <p>Type: Boolean 21763d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 21863d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 21963d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova * @see #getUserRestrictions() 22063d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova */ 22163d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova public static final String DISALLOW_BLUETOOTH = "no_bluetooth"; 22263d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova 22363d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova /** 2244f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov * Specifies if outgoing bluetooth sharing is disallowed on the device. Device owner and profile 2254f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov * owner can set this restriction. When it is set by device owner, all users on this device will 2264f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov * be affected. 2274f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov * 2284f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov * <p>Default is <code>true</code> for managed profiles and false for otherwise. When a device 2294f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov * upgrades to {@link android.os.Build.VERSION_CODES#O}, the system sets it for all existing 2304f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov * managed profiles. 2314f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov * 2324f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov * <p>Key for user restrictions. 2334f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov * <p>Type: Boolean 2344f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 2354f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 2364f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov * @see #getUserRestrictions() 2374f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov */ 2384f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov public static final String DISALLOW_BLUETOOTH_SHARING = "no_bluetooth_sharing"; 2394f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov 2404f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov /** 24126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from transferring files over 242c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * USB. This can only be set by device owners and profile owners on the primary user. 243c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 24426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 2450ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 2460ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 247068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 248068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 249a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #getUserRestrictions() 250a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 251a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer"; 252a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 253b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier /** 25426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring user 255b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * credentials. The default value is <code>false</code>. 25626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 2570ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 2580ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 259068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 260068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 261b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * @see #getUserRestrictions() 262b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier */ 263b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials"; 264b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier 265b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier /** 266150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * When set on the primary user this specifies if the user can remove other users. 267150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * When set on a secondary user, this specifies if the user can remove itself. 268150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * This restriction has no effect on managed profiles. 269150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * The default value is <code>false</code>. 27026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 2710ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 2720ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 273068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 274068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 275b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * @see #getUserRestrictions() 276b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier */ 277b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier public static final String DISALLOW_REMOVE_USER = "no_remove_user"; 278b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier 279d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 2806c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera * Specifies if managed profiles of this user can be removed, other than by its profile owner. 2816c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera * The default value is <code>false</code>. 2826c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera * <p> 2832ea46fe658c5a977a11372d7180e8ed9abf261e8Nicolas Prevot * This restriction has no effect on managed profiles. 2846c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera * 2856c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera * <p>Key for user restrictions. 2866c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera * <p>Type: Boolean 2876c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 2886c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 2896c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera * @see #getUserRestrictions() 2906c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera */ 2916c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera public static final String DISALLOW_REMOVE_MANAGED_PROFILE = "no_remove_managed_profile"; 2926c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera 2936c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera /** 29426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from enabling or 295d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * accessing debugging features. The default value is <code>false</code>. 29626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 2970ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 2980ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 299068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 300068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 301d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 302d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 303d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features"; 304d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 305d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 30626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring VPN. 307d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * The default value is <code>false</code>. 308298f98fa234f353267ddc9c75d58e8cc542c25f1Nicolas Prevot * This restriction has an effect in a managed profile only from 3090e3de6cacaffcfeda4d6353be61e2f1f9ed80705Dianne Hackborn * {@link android.os.Build.VERSION_CODES#M} 31026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 3110ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 3120ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 313068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 314068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 315d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 316d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 317d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_CONFIG_VPN = "no_config_vpn"; 318d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 319d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 32026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring Tethering 321c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * & portable hotspots. This can only be set by device owners and profile owners on the 322c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * primary user. The default value is <code>false</code>. 32326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 3240ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 3250ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 326068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 327068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 328d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 329d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 330d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering"; 331d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 332d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 333e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * Specifies if a user is disallowed from resetting network settings 334e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * from Settings. This can only be set by device owners and profile owners on the primary user. 335e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * The default value is <code>false</code>. 3360ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect on secondary users and managed profiles since only the 337e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * primary user can reset the network settings of the device. 338e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * 3390ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 3400ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 341068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 342068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 343e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * @see #getUserRestrictions() 344e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott */ 345e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott public static final String DISALLOW_NETWORK_RESET = "no_network_reset"; 346e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott 347e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott /** 34826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from factory resetting 349c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * from Settings. This can only be set by device owners and profile owners on the primary user. 350c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 3510ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect on secondary users and managed profiles since only the 352150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * primary user can factory reset the device. 35326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 3540ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 3550ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 356068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 357068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 358d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 359d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 360d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_FACTORY_RESET = "no_factory_reset"; 361d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 362d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 3636c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera * Specifies if a user is disallowed from adding new users. This can only be set by device 3646c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera * owners and profile owners on the primary user. 365c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 3660ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect on secondary users and managed profiles since only the 367150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * primary user can add other users. 36826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 3690ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 3700ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 371068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 372068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 373d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 374d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 375d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_ADD_USER = "no_add_user"; 376d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 377d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 3786c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera * Specifies if a user is disallowed from adding managed profiles. 3796c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera * <p>The default value for an unmanaged user is <code>false</code>. 3802ea46fe658c5a977a11372d7180e8ed9abf261e8Nicolas Prevot * For users with a device owner set, the default is <code>true</code>. 3812ea46fe658c5a977a11372d7180e8ed9abf261e8Nicolas Prevot * <p>This restriction has no effect on managed profiles. 3826c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera * 3836c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera * <p>Key for user restrictions. 3846c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera * <p>Type: Boolean 3856c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 3866c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 3876c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera * @see #getUserRestrictions() 3886c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera */ 3896c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera public static final String DISALLOW_ADD_MANAGED_PROFILE = "no_add_managed_profile"; 3906c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera 3916c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera /** 3929f592dbca32c698cabcf38a5e07cbb118fbf44ddRubin Xu * Specifies if a user is disallowed from disabling application verification. 3939f592dbca32c698cabcf38a5e07cbb118fbf44ddRubin Xu * Starting from {@link android.os.Build.VERSION_CODES#O}, application verification 3949f592dbca32c698cabcf38a5e07cbb118fbf44ddRubin Xu * is enforced across all users on the device if a profile owner or device owner sets 3959f592dbca32c698cabcf38a5e07cbb118fbf44ddRubin Xu * this restriction to <code>true</code>. The default value is <code>false</code>. 39626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 3970ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 3980ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 399068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 400068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 401d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 402d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 403d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps"; 404d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 405d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 40626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring cell 407c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * broadcasts. This can only be set by device owners and profile owners on the primary user. 408c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 4090ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect on secondary users and managed profiles since only the 410150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * primary user can configure cell broadcasts. 41126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 4120ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 4130ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 414068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 415068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 416d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 417d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 418d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts"; 419d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 420d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 42126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring mobile 422c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * networks. This can only be set by device owners and profile owners on the primary user. 423c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 4240ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect on secondary users and managed profiles since only the 425150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * primary user can configure mobile networks. 42626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 4270ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 4280ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 429068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 430068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 431d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 432d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 433d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks"; 434d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 435d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 43626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from modifying 437c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * applications in Settings or launchers. The following actions will not be allowed when this 438c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * restriction is enabled: 439c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>uninstalling apps</li> 440c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>disabling apps</li> 441c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>clearing app caches</li> 442c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>clearing app data</li> 443c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>force stopping apps</li> 444c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>clearing app defaults</li> 445c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <p> 446c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * The default value is <code>false</code>. 44726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 4488bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera * <p><strong>Note:</strong> The user will still be able to perform those actions via other 4498bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera * means (such as adb). Third party apps will also be able to uninstall apps via the 4508bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera * {@link android.content.pm.PackageInstaller}. {@link #DISALLOW_UNINSTALL_APPS} or 4518bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera * {@link DevicePolicyManager#setUninstallBlocked(ComponentName, String, boolean)} should be 4528bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera * used to prevent the user from uninstalling apps completely, and 4538bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera * {@link DevicePolicyManager#addPersistentPreferredActivity(ComponentName, IntentFilter, ComponentName)} 4548bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera * to add a default intent handler for a given intent filter. 4558bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera * 4560ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 4570ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 458068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 459068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 460d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 461d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 46236fbc8d6453da438a8ab83352ff1bcfcba5f25b5Julia Reynolds public static final String DISALLOW_APPS_CONTROL = "no_control_apps"; 463d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 464394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier /** 46526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from mounting 466c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * physical external media. This can only be set by device owners and profile owners on the 467c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * primary user. The default value is <code>false</code>. 46826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 4690ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 4700ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 471068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 472068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 473394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier * @see #getUserRestrictions() 474394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier */ 475394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media"; 476394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier 477394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier /** 478ce3e1a3c5fb881ebdea6ba219dae68c9b63ba108Pavel Grafov * Specifies if a user is disallowed from adjusting microphone volume. If set, the microphone 479ce3e1a3c5fb881ebdea6ba219dae68c9b63ba108Pavel Grafov * will be muted. This can be set by device owners and profile owners. The default value is 480ce3e1a3c5fb881ebdea6ba219dae68c9b63ba108Pavel Grafov * <code>false</code>. 48126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 482ce3e1a3c5fb881ebdea6ba219dae68c9b63ba108Pavel Grafov * <p>This restriction has no effect on managed profiles. 4830ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 4840ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 485068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 486068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 487394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier * @see #getUserRestrictions() 488394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier */ 489394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone"; 490394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier 491394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier /** 492ce3e1a3c5fb881ebdea6ba219dae68c9b63ba108Pavel Grafov * Specifies if a user is disallowed from adjusting the master volume. If set, the master volume 493ce3e1a3c5fb881ebdea6ba219dae68c9b63ba108Pavel Grafov * will be muted. This can be set by device owners and profile owners. The default value is 494ce3e1a3c5fb881ebdea6ba219dae68c9b63ba108Pavel Grafov * <code>false</code>. 49526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 496ce3e1a3c5fb881ebdea6ba219dae68c9b63ba108Pavel Grafov * <p>This restriction has no effect on managed profiles. 4970ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 4980ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 499068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 500068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 501394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier * @see #getUserRestrictions() 502394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier */ 503394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume"; 504394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier 5059f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani /** 50626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies that the user is not allowed to make outgoing 507390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani * phone calls. Emergency calls are still permitted. 508390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani * The default value is <code>false</code>. 509eb83ab52b28766adf1743db76484515bc9b9e08aTony Mak * <p>This restriction has no effect on managed profiles. 51026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 5110ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 5120ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 513068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 514068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 515390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani * @see #getUserRestrictions() 516390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani */ 517390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls"; 518390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani 519390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani /** 52026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies that the user is not allowed to send or receive 521c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * SMS messages. The default value is <code>false</code>. 52226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 5230ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 5240ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 525068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 526068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 5279f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani * @see #getUserRestrictions() 5289f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani */ 529390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani public static final String DISALLOW_SMS = "no_sms"; 5309f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani 5311c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk /** 5322cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * Specifies if the user is not allowed to have fun. In some cases, the 5332cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * device owner may wish to prevent the user from experiencing amusement or 5342cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * joy while using the device. The default value is <code>false</code>. 5352cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * 5360ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 5370ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 538068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 539068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 5402cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * @see #getUserRestrictions() 5412cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey */ 5422cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey public static final String DISALLOW_FUN = "no_fun"; 5432cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey 5442cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey /** 54526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies that windows besides app windows should not be 5461c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * created. This will block the creation of the following types of windows. 5471c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_TOAST}</li> 5481c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_PHONE}</li> 5491c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li> 5501c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li> 5511c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li> 5521c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li> 5535cd907d3d6ceebf8731ef1f69347cce6f76109e9Wale Ogunwale * <li>{@link LayoutParams#TYPE_APPLICATION_OVERLAY}</li> 5541c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * 555c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * <p>This can only be set by device owners and profile owners on the primary user. 556c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 55726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 5580ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 5590ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 560068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 561068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 5621c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * @see #getUserRestrictions() 5631c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk */ 5641c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows"; 5651c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk 566f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot /** 56726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if what is copied in the clipboard of this profile can 568f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be 569f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot * pasted in this profile. 570f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot * The default value is <code>false</code>. 57126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 5720ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 5730ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 574068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 575068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 576f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot * @see #getUserRestrictions() 577f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot */ 578f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste"; 579f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot 58026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani /** 58126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if the user is not allowed to use NFC to beam out data from apps. 58226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * The default value is <code>false</code>. 58326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 5840ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 5850ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 586068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 587068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 58826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * @see #getUserRestrictions() 58926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani */ 59026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam"; 59126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani 59253d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse /** 593f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * Hidden user restriction to disallow access to wallpaper manager APIs. This restriction 594f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * generally means that wallpapers are not supported for the particular user. This user 595f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * restriction is always set for managed profiles, because such profiles don't have wallpapers. 596f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz * @hide 597f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * @see #DISALLOW_SET_WALLPAPER 598068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 599068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 600f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz * @see #getUserRestrictions() 601f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz */ 602f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz public static final String DISALLOW_WALLPAPER = "no_wallpaper"; 603f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz 604f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz /** 605f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * User restriction to disallow setting a wallpaper. Profile owner and device owner 606f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * are able to set wallpaper regardless of this restriction. 607f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * The default value is <code>false</code>. 608f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * 609f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * <p>Key for user restrictions. 610f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * <p>Type: Boolean 611f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 612f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 613f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * @see #getUserRestrictions() 614f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi */ 615f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi public static final String DISALLOW_SET_WALLPAPER = "no_set_wallpaper"; 616f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi 617f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi /** 618bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * Specifies if the user is not allowed to reboot the device into safe boot mode. 619bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * This can only be set by device owners and profile owners on the primary user. 620bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * The default value is <code>false</code>. 621bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * 6220ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 6230ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 624068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 625068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 626bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * @see #getUserRestrictions() 627bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz */ 628bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz public static final String DISALLOW_SAFE_BOOT = "no_safe_boot"; 629bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz 630bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz /** 631b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov * Specifies if a user is not allowed to record audio. This restriction is always enabled for 632b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov * background users. The default value is <code>false</code>. 633b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov * 634068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 635068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 636b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov * @see #getUserRestrictions() 637b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov * @hide 638b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov */ 639b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov public static final String DISALLOW_RECORD_AUDIO = "no_record_audio"; 640b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov 641b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov /** 6429cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * Specifies if a user is not allowed to run in the background and should be stopped during 6439cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * user switch. The default value is <code>false</code>. 6449cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * 6459cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * <p>This restriction can be set by device owners and profile owners. 6469cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * 6479cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 6489cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 6499cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * @see #getUserRestrictions() 6509cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * @hide 6519cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov */ 6529cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov public static final String DISALLOW_RUN_IN_BACKGROUND = "no_run_in_background"; 6539cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov 6549cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov /** 655759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * Specifies if a user is not allowed to use the camera. 656759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * 657759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 658759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 659759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * @see #getUserRestrictions() 660759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * @hide 661759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki */ 662759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki public static final String DISALLOW_CAMERA = "no_camera"; 663759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki 664759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki /** 665c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak * Specifies if a user is not allowed to unmute the device's master volume. 666c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak * 667c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak * @see DevicePolicyManager#setMasterVolumeMuted(ComponentName, boolean) 668c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 669c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak * @see #getUserRestrictions() 670c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak * @hide 671c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak */ 672492b4724fb42adf29f3978f01ebc5238f893d194Esteban Talavera public static final String DISALLOW_UNMUTE_DEVICE = "disallow_unmute_device"; 673c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak 674c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak /** 675dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra * Specifies if a user is not allowed to use cellular data when roaming. This can only be set by 676dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra * device owners. The default value is <code>false</code>. 677dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra * 678dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 679dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 680dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra * @see #getUserRestrictions() 681dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra */ 682dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra public static final String DISALLOW_DATA_ROAMING = "no_data_roaming"; 683dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra 684dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra /** 6857f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * Specifies if a user is not allowed to change their icon. Device owner and profile owner 6867f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * can set this restriction. When it is set by device owner, only the target user will be 6877f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * affected. The default value is <code>false</code>. 6887f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * 6897f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * <p>Key for user restrictions. 6907f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * <p>Type: Boolean 6917f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 6927f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 6937f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * @see #getUserRestrictions() 6947f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi */ 6957f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi public static final String DISALLOW_SET_USER_ICON = "no_set_user_icon"; 6967f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi 6977f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi /** 6983d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra * Specifies if a user is not allowed to enable the oem unlock setting. The default value is 699c48b20f8f1d3e07e8a931b195669b0ab8895006cEsteban Talavera * <code>false</code>. Setting this restriction has no effect if the bootloader is already 700c48b20f8f1d3e07e8a931b195669b0ab8895006cEsteban Talavera * unlocked. 7013d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra * 70212b0496944381437a1e9974b0e79f56e766bbbdcLenka Trochtova * <p>Not for use by third-party applications. 70312b0496944381437a1e9974b0e79f56e766bbbdcLenka Trochtova * 7043d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 7053d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 7063d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra * @see #getUserRestrictions() 7073b8b46f3a46ccf35a6bb6a828af0f2d011cc9abeAndrew Scull * @deprecated use {@link OemLockManager#setOemUnlockAllowedByCarrier(boolean, byte[])} instead. 7083d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra * @hide 7093d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra */ 7103b8b46f3a46ccf35a6bb6a828af0f2d011cc9abeAndrew Scull @Deprecated 71112b0496944381437a1e9974b0e79f56e766bbbdcLenka Trochtova @SystemApi 7123d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra public static final String DISALLOW_OEM_UNLOCK = "no_oem_unlock"; 7133d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra 7143d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra /** 715f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot * Allows apps in the parent profile to handle web links from the managed profile. 716f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot * 7179edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * This user restriction has an effect only in a managed profile. 7189edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * If set: 7199edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * Intent filters of activities in the parent profile with action 7209edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * {@link android.content.Intent#ACTION_VIEW}, 7219edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which 7229edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * define a host can handle intents from the managed profile. 7239edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * The default value is <code>false</code>. 7249edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * 7250ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 7260ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 727068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 728068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 7299edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * @see #getUserRestrictions() 7309edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot */ 731f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot public static final String ALLOW_PARENT_PROFILE_APP_LINKING 732f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot = "allow_parent_profile_app_linking"; 7339edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot 7349edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot /** 73524d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme * Specifies if a user is not allowed to use Autofill Services. 73624d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme * 73724d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme * <p>Device owner and profile owner can set this restriction. When it is set by device owner, 73824d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme * only the target user will be affected. 73924d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme * 74024d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme * <p>The default value is <code>false</code>. 74124d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme * 74224d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 74324d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 74424d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme * @see #getUserRestrictions() 74524d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme */ 74624d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme public static final String DISALLOW_AUTOFILL = "no_autofill"; 74724d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme 74824d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme /** 74953d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * Application restriction key that is used to indicate the pending arrival 75053d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * of real restrictions for the app. 75153d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * 75253d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * <p> 75353d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * Applications that support restrictions should check for the presence of this key. 75453d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * A <code>true</code> value indicates that restrictions may be applied in the near 75553d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * future but are not available yet. It is the responsibility of any 75653d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * management application that sets this flag to update it when the final 75753d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * restrictions are enforced. 75853d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * 7590ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for application restrictions. 7600ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 761b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions( 762b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot * android.content.ComponentName, String, Bundle) 763b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions( 764b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot * android.content.ComponentName, String) 76553d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse */ 76653d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending"; 76753d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse 76812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani private static final String ACTION_CREATE_USER = "android.os.action.CREATE_USER"; 76912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 77012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 77112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Extra containing a name for the user being created. Optional parameter passed to 77212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * ACTION_CREATE_USER activity. 77312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 77412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 77512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public static final String EXTRA_USER_NAME = "android.os.extra.USER_NAME"; 77612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 77712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 77812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Extra containing account name for the user being created. Optional parameter passed to 77912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * ACTION_CREATE_USER activity. 78012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 78112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 78212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public static final String EXTRA_USER_ACCOUNT_NAME = "android.os.extra.USER_ACCOUNT_NAME"; 78312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 78412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 78512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Extra containing account type for the user being created. Optional parameter passed to 78612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * ACTION_CREATE_USER activity. 78712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 78812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 78912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public static final String EXTRA_USER_ACCOUNT_TYPE = "android.os.extra.USER_ACCOUNT_TYPE"; 79012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 79112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 79212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Extra containing account-specific data for the user being created. Optional parameter passed 79312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * to ACTION_CREATE_USER activity. 79412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 79512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 79612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public static final String EXTRA_USER_ACCOUNT_OPTIONS 79712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani = "android.os.extra.USER_ACCOUNT_OPTIONS"; 79812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 799655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** @hide */ 800655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3; 801655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** @hide */ 802655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2; 803655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** @hide */ 804655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani public static final int PIN_VERIFICATION_SUCCESS = -1; 805655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani 80637ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani /** 807e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki * Sent when user restrictions have changed. 808e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki * 809e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki * @hide 810e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki */ 811e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki @SystemApi 812e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki @TestApi // To allow seeing it from CTS. 813e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki public static final String ACTION_USER_RESTRICTIONS_CHANGED = 814e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki "android.os.action.USER_RESTRICTIONS_CHANGED"; 815e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki 816e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki /** 81737ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * Error result indicating that this user is not allowed to add other users on this device. 81837ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * This is a result code returned from the activity created by the intent 81937ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}. 82037ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani */ 82137ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani public static final int USER_CREATION_FAILED_NOT_PERMITTED = Activity.RESULT_FIRST_USER; 82237ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani 82337ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani /** 82437ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * Error result indicating that no more users can be created on this device. 82537ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * This is a result code returned from the activity created by the intent 82637ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}. 82737ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani */ 82837ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani public static final int USER_CREATION_FAILED_NO_MORE_USERS = Activity.RESULT_FIRST_USER + 1; 82937ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani 8307e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani /** @hide */ 831c0688301de5feea94c8456b3b9b42c41d0045f03Amith Yamasani public static UserManager get(Context context) { 832c0688301de5feea94c8456b3b9b42c41d0045f03Amith Yamasani return (UserManager) context.getSystemService(Context.USER_SERVICE); 83327db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani } 834a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 835258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** @hide */ 836258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public UserManager(Context context, IUserManager service) { 837258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mService = service; 8385200e1cb07190a1f6874d72a4561064cad3ee3e0Fyodor Kupolov mContext = context.getApplicationContext(); 839258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 840258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 841258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 8420696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * Returns whether this device supports multiple users with their own login and customizable 8430696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * space. 8440696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * @return whether the device supports multiple users. 845258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 8464673e7ea8d1f869910a9c0f9c211d4d27ad50b41Jeff Sharkey public static boolean supportsMultipleUsers() { 8471a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy return getMaxSupportedUsers() > 1 8481a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy && SystemProperties.getBoolean("fw.show_multiuserui", 8491a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI)); 850258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 851258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 8526794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall /** 8537cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen * @hide 8547cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen * @return Whether the device is running with split system user. It means the system user and 8557cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen * primary user are two separate users. Previously system user and primary user are combined as 8567cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen * a single owner user. see @link {android.os.UserHandle#USER_OWNER} 8577cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen */ 8587cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen public static boolean isSplitSystemUser() { 859aa67f684ff43c81e3280c846245ec6ebe907787eJohn Reck return RoSystemProperties.FW_SYSTEM_USER_SPLIT; 8607cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen } 8617cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen 8627cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen /** 86313a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky * @return Whether guest user is always ephemeral 86413a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky * @hide 86513a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky */ 86613a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky public static boolean isGuestUserEphemeral() { 86713a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky return Resources.getSystem() 86813a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky .getBoolean(com.android.internal.R.bool.config_guestUserEphemeral); 86913a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky } 87013a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky 87113a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky /** 872523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov * Returns whether switching users is currently allowed. 873523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov * <p>For instance switching users is not allowed if the current user is in a phone call, 874523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov * or system user hasn't been unlocked yet 875523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov * @hide 876523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov */ 877523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov public boolean canSwitchUsers() { 878523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov boolean allowUserSwitchingWhenSystemUserLocked = Settings.Global.getInt( 879523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov mContext.getContentResolver(), 880523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0; 881523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM); 882523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov boolean inCall = TelephonyManager.getDefault().getCallState() 883523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov != TelephonyManager.CALL_STATE_IDLE; 884523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall; 885523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov } 886523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov 887523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov /** 8885760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * Returns the user handle for the user that this process is running under. 889be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * 8905760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * @return the user handle of this process. 891258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 8926794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall */ 8938588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public @UserIdInt int getUserHandle() { 89479af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn return UserHandle.myUserId(); 895258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 896258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 897258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 8988832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn * Returns the user name of the user making this call. This call is only 8998832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn * available to applications on the system image; it requires the 9008832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn * MANAGE_USERS permission. 901258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the user name 902258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 903258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public String getUserName() { 904258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 905258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.getUserInfo(getUserHandle()).name; 906258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 907605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov throw re.rethrowFromSystemServer(); 908605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov } 909605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov } 910605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov 911605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov /** 912605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov * Returns whether user name has been set. 913605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov * <p>This method can be used to check that the value returned by {@link #getUserName()} was 914605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov * set by the user and is not a placeholder string provided by the system. 915605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov * @hide 916605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov */ 917605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov public boolean isUserNameSet() { 918605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov try { 919605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov return mService.isUserNameSet(getUserHandle()); 920605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov } catch (RemoteException re) { 921f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 922258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 923258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 924258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 92567a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn /** 926e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill * Used to determine whether the user making this call is subject to 927e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill * teleportations. 92867a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn * 929955d8d69ea6caabce1461dc25b339b9bf9dc61a6Dianne Hackborn * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can 93067a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn * now automatically identify goats using advanced goat recognition technology.</p> 93167a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn * 93267a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn * @return Returns true if the user making this call is a goat. 933e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill */ 934e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill public boolean isUserAGoat() { 935988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell return mContext.getPackageManager() 936988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell .isPackageAvailable("com.coffeestainstudios.goatsimulator"); 937e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill } 938df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 939df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani /** 94070f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * Used to check if this process is running under the primary user. The primary user 94170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * is the first human user on a device. 94270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * 94370f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * @return whether this process is running under the primary user. 94470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * @hide 94570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen */ 94670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen public boolean isPrimaryUser() { 94770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen UserInfo user = getUserInfo(UserHandle.myUserId()); 948d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani return user != null && user.isPrimary(); 94970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen } 95070f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen 95170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen /** 9525760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * Used to check if this process is running under the system user. The system user 9535760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * is the initial user that is implicitly created on first boot and hosts most of the 9545760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * system services. 9555760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * 9565760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * @return whether this process is running under the system user. 9575760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani */ 9585760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani public boolean isSystemUser() { 95970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen return UserHandle.myUserId() == UserHandle.USER_SYSTEM; 9605760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani } 9612b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen 9625760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani /** 963462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani * @hide 964462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani * Returns whether the caller is running as an admin user. There can be more than one admin 965462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani * user. 966462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani */ 967462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani public boolean isAdminUser() { 9682b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen return isUserAdmin(UserHandle.myUserId()); 9692b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen } 9702b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen 9712b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen /** 9722b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen * @hide 9732b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen * Returns whether the provided user is an admin user. There can be more than one admin 9742b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen * user. 9752b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen */ 9768588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean isUserAdmin(@UserIdInt int userId) { 9772b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen UserInfo user = getUserInfo(userId); 9782b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen return user != null && user.isAdmin(); 979462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani } 980462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani 981462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani /** 982e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani * Used to check if the user making this call is linked to another user. Linked users may have 98346bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani * a reduced number of available apps, app restrictions and account restrictions. 984e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani * @return whether the user making this call is a linked user 9852555dafce87e60fae28d71913730abf73e40fcd7Amith Yamasani * @hide 986df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani */ 987e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani public boolean isLinkedUser() { 988df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani try { 98971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani return mService.isRestricted(); 990df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } catch (RemoteException re) { 991f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 992df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 993df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 994df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 995258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 9961c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov * Checks if specified user can have restricted profile. 9971c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov * @hide 9981c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov */ 9998588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean canHaveRestrictedProfile(@UserIdInt int userId) { 10001c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov try { 10011c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov return mService.canHaveRestrictedProfile(userId); 10021c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov } catch (RemoteException re) { 1003f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 10041c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov } 10051c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov } 10061c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov 10071c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov /** 100813a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky * Checks if a user is a guest user. 100913a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky * @return whether user is a guest user. 101013a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky * @hide 101113a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky */ 101213a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky public boolean isGuestUser(int id) { 101313a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky UserInfo user = getUserInfo(id); 101413a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky return user != null && user.isGuest(); 101513a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky } 101613a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky 101713a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky /** 10181e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * Checks if the calling app is running as a guest user. 10191e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * @return whether the caller is a guest user. 10201e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * @hide 10211e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani */ 10221e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani public boolean isGuestUser() { 10231e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani UserInfo user = getUserInfo(UserHandle.myUserId()); 1024d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani return user != null && user.isGuest(); 1025d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani } 1026d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani 1027d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani /** 10281c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani * Checks if the calling app is running in a demo user. When running in a demo user, 10291c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani * apps can be more helpful to the user, or explain their features in more detail. 10301c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani * 1031d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani * @return whether the caller is a demo user. 1032d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani */ 1033d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani public boolean isDemoUser() { 10341c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani try { 10351c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani return mService.isDemoUser(UserHandle.myUserId()); 10361c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani } catch (RemoteException re) { 10371c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani throw re.rethrowFromSystemServer(); 10381c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani } 10391e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani } 10401e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani 10411e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani /** 10420e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani * Checks if the calling app is running in a managed profile. 10430e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani * 10440e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani * @return whether the caller is in a managed profile. 10450e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani * @hide 10460e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani */ 10470e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani @SystemApi 1048d86b8fea43ebb6e5c31691b44d8ceb0d8d3c9072Jeff Sharkey @RequiresPermission(android.Manifest.permission.MANAGE_USERS) 10490e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani public boolean isManagedProfile() { 1050d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki // No need for synchronization. Once it becomes non-null, it'll be non-null forever. 1051d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki // Worst case we might end up calling the AIDL method multiple times but that's fine. 1052d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki if (mIsManagedProfileCached != null) { 1053d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki return mIsManagedProfileCached; 1054d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki } 10558673b2899e775014336efff44ea88dcac2b25bddTony Mak try { 1056d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki mIsManagedProfileCached = mService.isManagedProfile(UserHandle.myUserId()); 1057d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki return mIsManagedProfileCached; 10588673b2899e775014336efff44ea88dcac2b25bddTony Mak } catch (RemoteException re) { 10598673b2899e775014336efff44ea88dcac2b25bddTony Mak throw re.rethrowFromSystemServer(); 10608673b2899e775014336efff44ea88dcac2b25bddTony Mak } 10618673b2899e775014336efff44ea88dcac2b25bddTony Mak } 10628673b2899e775014336efff44ea88dcac2b25bddTony Mak 10638673b2899e775014336efff44ea88dcac2b25bddTony Mak /** 10648673b2899e775014336efff44ea88dcac2b25bddTony Mak * Checks if the specified user is a managed profile. 10658673b2899e775014336efff44ea88dcac2b25bddTony Mak * Requires {@link android.Manifest.permission#MANAGE_USERS} permission, otherwise the caller 10668673b2899e775014336efff44ea88dcac2b25bddTony Mak * must be in the same profile group of specified user. 10678673b2899e775014336efff44ea88dcac2b25bddTony Mak * 10688673b2899e775014336efff44ea88dcac2b25bddTony Mak * @return whether the specified user is a managed profile. 10698673b2899e775014336efff44ea88dcac2b25bddTony Mak * @hide 10708673b2899e775014336efff44ea88dcac2b25bddTony Mak */ 10718673b2899e775014336efff44ea88dcac2b25bddTony Mak @SystemApi 1072d86b8fea43ebb6e5c31691b44d8ceb0d8d3c9072Jeff Sharkey @RequiresPermission(android.Manifest.permission.MANAGE_USERS) 10738673b2899e775014336efff44ea88dcac2b25bddTony Mak public boolean isManagedProfile(@UserIdInt int userId) { 1074d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki if (userId == UserHandle.myUserId()) { 1075d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki return isManagedProfile(); 1076d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki } 10778673b2899e775014336efff44ea88dcac2b25bddTony Mak try { 10788673b2899e775014336efff44ea88dcac2b25bddTony Mak return mService.isManagedProfile(userId); 10798673b2899e775014336efff44ea88dcac2b25bddTony Mak } catch (RemoteException re) { 10808673b2899e775014336efff44ea88dcac2b25bddTony Mak throw re.rethrowFromSystemServer(); 10818673b2899e775014336efff44ea88dcac2b25bddTony Mak } 10820e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani } 10830e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani 10840e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani /** 108502c8990bd6125f05cb32561727d559dc9327a601Kenny Guy * Gets badge for a managed profile. 108602c8990bd6125f05cb32561727d559dc9327a601Kenny Guy * Requires {@link android.Manifest.permission#MANAGE_USERS} permission, otherwise the caller 108702c8990bd6125f05cb32561727d559dc9327a601Kenny Guy * must be in the same profile group of specified user. 108802c8990bd6125f05cb32561727d559dc9327a601Kenny Guy * 108902c8990bd6125f05cb32561727d559dc9327a601Kenny Guy * @return which badge to use for the managed profile badge id will be less than 109002c8990bd6125f05cb32561727d559dc9327a601Kenny Guy * UserManagerService.getMaxManagedProfiles() 109102c8990bd6125f05cb32561727d559dc9327a601Kenny Guy * @hide 109202c8990bd6125f05cb32561727d559dc9327a601Kenny Guy */ 109302c8990bd6125f05cb32561727d559dc9327a601Kenny Guy public int getManagedProfileBadge(@UserIdInt int userId) { 109402c8990bd6125f05cb32561727d559dc9327a601Kenny Guy try { 109502c8990bd6125f05cb32561727d559dc9327a601Kenny Guy return mService.getManagedProfileBadge(userId); 109602c8990bd6125f05cb32561727d559dc9327a601Kenny Guy } catch (RemoteException re) { 109702c8990bd6125f05cb32561727d559dc9327a601Kenny Guy throw re.rethrowFromSystemServer(); 109802c8990bd6125f05cb32561727d559dc9327a601Kenny Guy } 109902c8990bd6125f05cb32561727d559dc9327a601Kenny Guy } 110002c8990bd6125f05cb32561727d559dc9327a601Kenny Guy 110102c8990bd6125f05cb32561727d559dc9327a601Kenny Guy /** 1102c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova * Checks if the calling app is running as an ephemeral user. 1103c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova * 1104c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova * @return whether the caller is an ephemeral user. 1105c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova * @hide 1106c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova */ 1107c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova public boolean isEphemeralUser() { 1108c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova return isUserEphemeral(UserHandle.myUserId()); 1109c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova } 1110c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova 1111c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova /** 1112c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova * Returns whether the specified user is ephemeral. 1113c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova * @hide 1114c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova */ 11158588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean isUserEphemeral(@UserIdInt int userId) { 1116c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova final UserInfo user = getUserInfo(userId); 1117c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova return user != null && user.isEphemeral(); 1118c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova } 1119c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova 1120c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova /** 1121a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * Return whether the given user is actively running. This means that 1122a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * the user is in the "started" state, not "stopped" -- it is currently 1123a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * allowed to run code through scheduled alarms, receiving broadcasts, 1124a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * etc. A started user may be either the current foreground user or a 1125a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * background user; the result here does not distinguish between the two. 11265eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki * 11275eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki * <p>Note prior to Android Nougat MR1 (SDK version <= 24; 11285eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki * {@link android.os.Build.VERSION_CODES#N), this API required a system permission 11295eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki * in order to check other profile's status. 11305eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki * Since Android Nougat MR1 (SDK version >= 25; 11315eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki * {@link android.os.Build.VERSION_CODES#N_MR1)), the restriction has been relaxed, and now 11325eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki * it'll accept any {@link UserHandle} within the same profile group as the caller. 1133cdb3c2fd0420daa6d26a733df0ec8dcc79676402Fyodor Kupolov * 1134a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * @param user The user to retrieve the running state for. 1135a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn */ 11365eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki // Note this requires either INTERACT_ACROSS_USERS or MANAGE_USERS. 1137a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn public boolean isUserRunning(UserHandle user) { 11380e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey return isUserRunning(user.getIdentifier()); 11390e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey } 11400e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey 11410e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey /** {@hide} */ 11422e7e09685a69cc6b9e3418065507c6c7f843b446Fyodor Kupolov public boolean isUserRunning(@UserIdInt int userId) { 1143a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn try { 11442e7e09685a69cc6b9e3418065507c6c7f843b446Fyodor Kupolov return mService.isUserRunning(userId); 114527b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 1146f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1147a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 1148a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 1149a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn 1150a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn /** 1151a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * Return whether the given user is actively running <em>or</em> stopping. 1152a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * This is like {@link #isUserRunning(UserHandle)}, but will also return 1153a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * true if the user had been running but is in the process of being stopped 1154a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * (but is not yet fully stopped, and still running some code). 11555eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki * 11565eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki * <p>Note prior to Android Nougat MR1 (SDK version <= 24; 11575eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki * {@link android.os.Build.VERSION_CODES#N), this API required a system permission 11585eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki * in order to check other profile's status. 11595eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki * Since Android Nougat MR1 (SDK version >= 25; 11605eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki * {@link android.os.Build.VERSION_CODES#N_MR1)), the restriction has been relaxed, and now 11615eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki * it'll accept any {@link UserHandle} within the same profile group as the caller. 1162cdb3c2fd0420daa6d26a733df0ec8dcc79676402Fyodor Kupolov * 1163a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * @param user The user to retrieve the running state for. 1164a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn */ 11655eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki // Note this requires either INTERACT_ACROSS_USERS or MANAGE_USERS. 1166a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn public boolean isUserRunningOrStopping(UserHandle user) { 1167a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn try { 1168e17ac1569793c333bb4dce86607a342e7c982ae7Jeff Sharkey // TODO: reconcile stopped vs stopping? 1169dc589ac82b5fe2063f4cfd94c8ae26d43d5420a0Sudheer Shanka return ActivityManager.getService().isUserRunning( 1170e17ac1569793c333bb4dce86607a342e7c982ae7Jeff Sharkey user.getIdentifier(), ActivityManager.FLAG_OR_STOPPED); 117127b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 1172f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1173a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 1174a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 1175a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn 11760825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey /** 1177cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * Return whether the calling user is running in an "unlocked" state. 1178cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * <p> 1179cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * On devices with direct boot, a user is unlocked only after they've 1180cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * entered their credentials (such as a lock pattern or PIN). On devices 1181cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * without direct boot, a user is unlocked as soon as it starts. 1182cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * <p> 1183cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * When a user is locked, only device-protected data storage is available. 1184cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * When a user is unlocked, both device-protected and credential-protected 1185cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * private app data storage is available. 11868a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey * 11878a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey * @see Intent#ACTION_USER_UNLOCKED 11888a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey * @see Context#createDeviceProtectedStorageContext() 1189b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey */ 1190b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey public boolean isUserUnlocked() { 1191b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey return isUserUnlocked(Process.myUserHandle()); 1192b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey } 1193b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey 1194b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey /** 1195cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * Return whether the given user is running in an "unlocked" state. 1196cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * <p> 1197cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * On devices with direct boot, a user is unlocked only after they've 1198cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * entered their credentials (such as a lock pattern or PIN). On devices 1199cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * without direct boot, a user is unlocked as soon as it starts. 1200cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * <p> 1201cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * When a user is locked, only device-protected data storage is available. 1202cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * When a user is unlocked, both device-protected and credential-protected 1203cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * private app data storage is available. 1204cdb3c2fd0420daa6d26a733df0ec8dcc79676402Fyodor Kupolov * <p>Requires {@code android.permission.MANAGE_USERS} or 1205cdb3c2fd0420daa6d26a733df0ec8dcc79676402Fyodor Kupolov * {@code android.permission.INTERACT_ACROSS_USERS}, otherwise specified {@link UserHandle user} 1206cdb3c2fd0420daa6d26a733df0ec8dcc79676402Fyodor Kupolov * must be the calling user or a managed profile associated with it. 1207b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey * 1208b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey * @param user to retrieve the unlocked state for. 12098a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey * @see Intent#ACTION_USER_UNLOCKED 12108a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey * @see Context#createDeviceProtectedStorageContext() 1211b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey */ 1212b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey public boolean isUserUnlocked(UserHandle user) { 12130999c0d6e9c83873d9595ee764b6388dbc49dcb8Jeff Sharkey return isUserUnlocked(user.getIdentifier()); 12140999c0d6e9c83873d9595ee764b6388dbc49dcb8Jeff Sharkey } 12150999c0d6e9c83873d9595ee764b6388dbc49dcb8Jeff Sharkey 12160999c0d6e9c83873d9595ee764b6388dbc49dcb8Jeff Sharkey /** {@hide} */ 12178588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean isUserUnlocked(@UserIdInt int userId) { 1218ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey try { 12192e7e09685a69cc6b9e3418065507c6c7f843b446Fyodor Kupolov return mService.isUserUnlocked(userId); 1220ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey } catch (RemoteException re) { 1221ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey throw re.rethrowFromSystemServer(); 1222ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey } 1223ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey } 1224ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey 1225ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey /** {@hide} */ 1226ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey public boolean isUserUnlockingOrUnlocked(UserHandle user) { 1227ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey return isUserUnlockingOrUnlocked(user.getIdentifier()); 1228ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey } 1229ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey 1230ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey /** {@hide} */ 1231ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) { 1232ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey try { 1233c413f7078d2a69badcb4a2326a4a3d55c25da020Fyodor Kupolov return mService.isUserUnlockingOrUnlocked(userId); 1234ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey } catch (RemoteException re) { 1235ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey throw re.rethrowFromSystemServer(); 1236ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey } 1237b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey } 1238b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey 1239b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey /** 1240258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns the UserInfo object describing a specific user. 12418673b2899e775014336efff44ea88dcac2b25bddTony Mak * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1242258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the user handle of the user whose information is being requested. 1243258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the UserInfo object for a specific user. 1244258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1245b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn */ 12468588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public UserInfo getUserInfo(@UserIdInt int userHandle) { 1247258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 1248258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.getUserInfo(userHandle); 1249258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 1250f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1251258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1252258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1253258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 125471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 1255e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * @hide 1256e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * 1257e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * Returns who set a user restriction on a user. 1258e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * @param restrictionKey the string key representing the restriction 1259e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 1260e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * @return The source of user restriction. Any combination of {@link #RESTRICTION_NOT_SET}, 1261e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * {@link #RESTRICTION_SOURCE_SYSTEM}, {@link #RESTRICTION_SOURCE_DEVICE_OWNER} 1262e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * and {@link #RESTRICTION_SOURCE_PROFILE_OWNER} 12636a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * @deprecated use {@link #getUserRestrictionSources(String, int)} instead. 1264e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban */ 12656a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov @Deprecated 1266e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban @SystemApi 1267e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban @UserRestrictionSource 1268d86b8fea43ebb6e5c31691b44d8ceb0d8d3c9072Jeff Sharkey @RequiresPermission(android.Manifest.permission.MANAGE_USERS) 1269e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban public int getUserRestrictionSource(String restrictionKey, UserHandle userHandle) { 1270e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban try { 1271e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban return mService.getUserRestrictionSource(restrictionKey, userHandle.getIdentifier()); 1272e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban } catch (RemoteException re) { 1273e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban throw re.rethrowFromSystemServer(); 1274e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban } 1275e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban } 1276e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban 1277e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban /** 12786a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * @hide 12796a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * 12806a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * Returns a list of users who set a user restriction on a given user. 12816a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * @param restrictionKey the string key representing the restriction 12826a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 12836a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * @return a list of user ids enforcing this restriction. 12846a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov */ 12856a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov @SystemApi 1286d86b8fea43ebb6e5c31691b44d8ceb0d8d3c9072Jeff Sharkey @RequiresPermission(android.Manifest.permission.MANAGE_USERS) 12876a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov public List<EnforcingUser> getUserRestrictionSources( 12886a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov String restrictionKey, UserHandle userHandle) { 12896a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov try { 12906a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov return mService.getUserRestrictionSources(restrictionKey, userHandle.getIdentifier()); 12916a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov } catch (RemoteException re) { 12926a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov throw re.rethrowFromSystemServer(); 12936a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov } 12946a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov } 12956a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov 12966a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov /** 129771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Returns the user-wide restrictions imposed on this user. 129871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @return a Bundle containing all the restrictions. 129971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 1300e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public Bundle getUserRestrictions() { 1301e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani return getUserRestrictions(Process.myUserHandle()); 1302e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 1303e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 130471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 130571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>. 130671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 130771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @return a Bundle containing all the restrictions. 130871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 1309e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public Bundle getUserRestrictions(UserHandle userHandle) { 1310e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani try { 1311e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani return mService.getUserRestrictions(userHandle.getIdentifier()); 1312e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } catch (RemoteException re) { 1313f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1314e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 1315e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 1316e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 13173bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban /** 13183bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban * @hide 13193bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban * Returns whether the given user has been disallowed from performing certain actions 13203bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban * or setting certain settings through UserManager. This method disregards restrictions 13213bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban * set by device policy. 13223bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban * @param restrictionKey the string key representing the restriction 13233bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 13243bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban */ 13253bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban public boolean hasBaseUserRestriction(String restrictionKey, UserHandle userHandle) { 13263bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban try { 13273bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban return mService.hasBaseUserRestriction(restrictionKey, userHandle.getIdentifier()); 13283bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban } catch (RemoteException re) { 1329f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 13303bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban } 13313bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban } 13323bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban 133371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 1334a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki * This will no longer work. Device owners and profile owners should use 1335a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead. 133671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 1337a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki // System apps should use UserManager.setUserRestriction() instead. 13383d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds @Deprecated 1339e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public void setUserRestrictions(Bundle restrictions) { 1340068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki throw new UnsupportedOperationException("This method is no longer supported"); 1341e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 1342e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 134371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 1344a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki * This will no longer work. Device owners and profile owners should use 1345a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead. 134671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 1347a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki // System apps should use UserManager.setUserRestriction() instead. 13483d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds @Deprecated 1349e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) { 1350068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki throw new UnsupportedOperationException("This method is no longer supported"); 1351e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 1352e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 135371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 135471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Sets the value of a specific restriction. 1355be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani * Requires the MANAGE_USERS permission. 135671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param key the key of the restriction 135771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param value the value for the restriction 13583d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction( 13593d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * android.content.ComponentName, String)} or 13603d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * {@link android.app.admin.DevicePolicyManager#clearUserRestriction( 13613d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * android.content.ComponentName, String)} instead. 136271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 13633d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds @Deprecated 136471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public void setUserRestriction(String key, boolean value) { 1365068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki setUserRestriction(key, value, Process.myUserHandle()); 136671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani } 136771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani 136871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 136971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @hide 137071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Sets the value of a specific restriction on a specific user. 1371be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani * Requires the MANAGE_USERS permission. 137271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param key the key of the restriction 137371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param value the value for the restriction 137471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param userHandle the user whose restriction is to be changed. 13753d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction( 13763d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * android.content.ComponentName, String)} or 13773d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * {@link android.app.admin.DevicePolicyManager#clearUserRestriction( 13783d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * android.content.ComponentName, String)} instead. 137971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 13803d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds @Deprecated 13816794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall public void setUserRestriction(String key, boolean value, UserHandle userHandle) { 1382b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov try { 1383b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov mService.setUserRestriction(key, value, userHandle.getIdentifier()); 1384b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov } catch (RemoteException re) { 1385f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1386b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov } 13876794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall } 13886794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 1389258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 1390a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * Returns whether the current user has been disallowed from performing certain actions 1391a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * or setting certain settings. 13922b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds * 13932b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds * @param restrictionKey The string key representing the restriction. 13942b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds * @return {@code true} if the current user has the given restriction, {@code false} otherwise. 1395a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 1396a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public boolean hasUserRestriction(String restrictionKey) { 1397b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie return hasUserRestriction(restrictionKey, Process.myUserHandle()); 1398b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie } 1399b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie 1400b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie /** 1401b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * @hide 1402b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * Returns whether the given user has been disallowed from performing certain actions 1403b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * or setting certain settings. 1404b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * @param restrictionKey the string key representing the restriction 1405b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 1406b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie */ 1407b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) { 14088cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani try { 14098cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani return mService.hasUserRestriction(restrictionKey, 14108cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani userHandle.getIdentifier()); 14118cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani } catch (RemoteException re) { 1412f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 14138cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani } 1414a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall } 1415a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 1416a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 141733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * Return the serial number for a user. This is a device-unique 1418b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * number assigned to that user; if the user is deleted and then a new 1419b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * user created, the new users will not be given the same serial number. 142033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @param user The user whose serial number is to be retrieved. 1421b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * @return The serial number of the given user; returns -1 if the 1422b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * given UserHandle does not exist. 142333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @see #getUserForSerialNumber(long) 142433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn */ 142533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn public long getSerialNumberForUser(UserHandle user) { 142633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn return getUserSerialNumber(user.getIdentifier()); 142733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn } 142833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn 142933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn /** 143033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * Return the user associated with a serial number previously 143133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * returned by {@link #getSerialNumberForUser(UserHandle)}. 143233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @param serialNumber The serial number of the user that is being 143333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * retrieved. 143433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @return Return the user associated with the serial number, or null 143533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * if there is not one. 143633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @see #getSerialNumberForUser(UserHandle) 143733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn */ 143833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn public UserHandle getUserForSerialNumber(long serialNumber) { 1439ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov int ident = getUserHandle((int) serialNumber); 144033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn return ident >= 0 ? new UserHandle(ident) : null; 144133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn } 144233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn 144333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn /** 1444cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen * Creates a user with the specified name and options. For non-admin users, default user 1445cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen * restrictions are going to be applied. 14461952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1447258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 1448258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param name the user's name 1449258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param flags flags that identify the type of user and other properties. 1450258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @see UserInfo 1451258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 1452258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the UserInfo object for the created user, or null if the user could not be created. 1453258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1454258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 1455258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public UserInfo createUser(String name, int flags) { 1456cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen UserInfo user = null; 1457258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 1458cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen user = mService.createUser(name, flags); 1459e9c440638e27a123a82feb5e4677ce1242785288phweiss // TODO: Keep this in sync with 1460e9c440638e27a123a82feb5e4677ce1242785288phweiss // UserManagerService.LocalService.createUserEvenWhenDisallowed 1461cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen if (user != null && !user.isAdmin()) { 1462068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki mService.setUserRestriction(DISALLOW_SMS, true, user.id); 1463068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki mService.setUserRestriction(DISALLOW_OUTGOING_CALLS, true, user.id); 1464cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen } 1465258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 1466f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1467258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1468cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen return user; 1469258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1470258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 1471258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 14721e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * Creates a guest user and configures it. 14731e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * @param context an application context 14741e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * @param name the name to set for the user 14751e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * @hide 14761e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani */ 14771e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani public UserInfo createGuest(Context context, String name) { 1478068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki UserInfo guest = null; 1479068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki try { 1480068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki guest = mService.createUser(name, UserInfo.FLAG_GUEST); 1481068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki if (guest != null) { 1482068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki Settings.Secure.putStringForUser(context.getContentResolver(), 1483068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id); 1484bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani } 1485068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki } catch (RemoteException re) { 1486f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 14871e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani } 14881e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani return guest; 14891e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani } 14901e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani 1491aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani /** 14922a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * Creates a user with the specified name and options as a profile of another user. 1493a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1494a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * 1495a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @param name the user's name 1496a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @param flags flags that identify the type of user and other properties. 14977cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka * @param userHandle new user will be a profile of this user. 1498a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * 14997cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka * @return the {@link UserInfo} object for the created user, or null if the user 15007cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka * could not be created. 1501a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @hide 1502a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy */ 15038588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle) { 15047cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka return createProfileForUser(name, flags, userHandle, null); 15057cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka } 15067cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka 15077cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka /** 15087cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka * Version of {@link #createProfileForUser(String, int, int)} that allows you to specify 15097cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka * any packages that should not be installed in the new profile by default, these packages can 15107cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka * still be installed later by the user if needed. 15117cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka * 15127cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka * @param name the user's name 15137cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka * @param flags flags that identify the type of user and other properties. 15147cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka * @param userHandle new user will be a profile of this user. 15157cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka * @param disallowedPackages packages that will not be installed in the profile being created. 15167cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka * 15177cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka * @return the {@link UserInfo} object for the created user, or null if the user 15187cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka * could not be created. 15197cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka * @hide 15207cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka */ 15217cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle, 15227cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka String[] disallowedPackages) { 1523a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy try { 15247cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka return mService.createProfileForUser(name, flags, userHandle, disallowedPackages); 1525a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } catch (RemoteException re) { 1526f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1527a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } 1528a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } 1529a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy 1530a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy /** 15316dc428f677f2b80b085466961e9495972e1c88c9Tony Mak * Similar to {@link #createProfileForUser(String, int, int, String[])} 15326c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera * except bypassing the checking of {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}. 15336dc428f677f2b80b085466961e9495972e1c88c9Tony Mak * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 15346dc428f677f2b80b085466961e9495972e1c88c9Tony Mak * 15356dc428f677f2b80b085466961e9495972e1c88c9Tony Mak * @see #createProfileForUser(String, int, int, String[]) 15366dc428f677f2b80b085466961e9495972e1c88c9Tony Mak * @hide 15376dc428f677f2b80b085466961e9495972e1c88c9Tony Mak */ 15386dc428f677f2b80b085466961e9495972e1c88c9Tony Mak public UserInfo createProfileForUserEvenWhenDisallowed(String name, int flags, 15396dc428f677f2b80b085466961e9495972e1c88c9Tony Mak @UserIdInt int userHandle, String[] disallowedPackages) { 15406dc428f677f2b80b085466961e9495972e1c88c9Tony Mak try { 15416dc428f677f2b80b085466961e9495972e1c88c9Tony Mak return mService.createProfileForUserEvenWhenDisallowed(name, flags, userHandle, 15426dc428f677f2b80b085466961e9495972e1c88c9Tony Mak disallowedPackages); 15436dc428f677f2b80b085466961e9495972e1c88c9Tony Mak } catch (RemoteException re) { 15446dc428f677f2b80b085466961e9495972e1c88c9Tony Mak throw re.rethrowFromSystemServer(); 15456dc428f677f2b80b085466961e9495972e1c88c9Tony Mak } 15466dc428f677f2b80b085466961e9495972e1c88c9Tony Mak } 15476dc428f677f2b80b085466961e9495972e1c88c9Tony Mak 15486dc428f677f2b80b085466961e9495972e1c88c9Tony Mak /** 154902cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov * Creates a restricted profile with the specified name. This method also sets necessary 155002cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov * restrictions and adds shared accounts. 155106a484adb93c6c969321147b07112684383305f6Fyodor Kupolov * 155206a484adb93c6c969321147b07112684383305f6Fyodor Kupolov * @param name profile's name 155306a484adb93c6c969321147b07112684383305f6Fyodor Kupolov * @return UserInfo object for the created user, or null if the user could not be created. 155406a484adb93c6c969321147b07112684383305f6Fyodor Kupolov * @hide 155506a484adb93c6c969321147b07112684383305f6Fyodor Kupolov */ 155606a484adb93c6c969321147b07112684383305f6Fyodor Kupolov public UserInfo createRestrictedProfile(String name) { 155706a484adb93c6c969321147b07112684383305f6Fyodor Kupolov try { 155802cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov UserHandle parentUserHandle = Process.myUserHandle(); 155902cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov UserInfo user = mService.createRestrictedProfile(name, 156002cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov parentUserHandle.getIdentifier()); 156102cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov if (user != null) { 156202cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov AccountManager.get(mContext).addSharedAccountsFromParentUser(parentUserHandle, 156302cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov UserHandle.of(user.id)); 156406a484adb93c6c969321147b07112684383305f6Fyodor Kupolov } 156502cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov return user; 156627b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 1567f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 156806a484adb93c6c969321147b07112684383305f6Fyodor Kupolov } 156906a484adb93c6c969321147b07112684383305f6Fyodor Kupolov } 157006a484adb93c6c969321147b07112684383305f6Fyodor Kupolov 157106a484adb93c6c969321147b07112684383305f6Fyodor Kupolov /** 15720696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * Returns an intent to create a user for the provided name and account name. The name 15730696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * and account name will be used when the setup process for the new user is started. 15740696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * <p> 157512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * The intent should be launched using startActivityForResult and the return result will 157637ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * indicate if the user consented to adding a new user and if the operation succeeded. Any 157737ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * errors in creating the user will be returned in the result code. If the user cancels the 157837ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * request, the return result will be {@link Activity#RESULT_CANCELED}. On success, the 157937ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * result code will be {@link Activity#RESULT_OK}. 15800696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * <p> 15810696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * Use {@link #supportsMultipleUsers()} to first check if the device supports this operation 15820696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * at all. 15830696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * <p> 158412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * The new user is created but not initialized. After switching into the user for the first 158512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * time, the preferred user name and account information are used by the setup process for that 158612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * user. 158712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * 158812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param userName Optional name to assign to the user. 15890696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * @param accountName Optional account name that will be used by the setup wizard to initialize 159012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * the user. 159112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param accountType Optional account type for the account to be created. This is required 159212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * if the account name is specified. 159312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param accountOptions Optional bundle of data to be passed in during account creation in the 159412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * new user via {@link AccountManager#addAccount(String, String, String[], 159512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Bundle, android.app.Activity, android.accounts.AccountManagerCallback, 159612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Handler)}. 15970696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * @return An Intent that can be launched from an Activity. 159837ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * @see #USER_CREATION_FAILED_NOT_PERMITTED 159937ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * @see #USER_CREATION_FAILED_NO_MORE_USERS 16000696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * @see #supportsMultipleUsers 160112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 160212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public static Intent createUserCreationIntent(@Nullable String userName, 160312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani @Nullable String accountName, 160412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani @Nullable String accountType, @Nullable PersistableBundle accountOptions) { 160512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani Intent intent = new Intent(ACTION_CREATE_USER); 160612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani if (userName != null) { 160712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani intent.putExtra(EXTRA_USER_NAME, userName); 160812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 160912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani if (accountName != null && accountType == null) { 161012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani throw new IllegalArgumentException("accountType must be specified if accountName is " 161112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani + "specified"); 161212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 161312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani if (accountName != null) { 161412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani intent.putExtra(EXTRA_USER_ACCOUNT_NAME, accountName); 161512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 161612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani if (accountType != null) { 161712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani intent.putExtra(EXTRA_USER_ACCOUNT_TYPE, accountType); 161812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 161912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani if (accountOptions != null) { 162012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani intent.putExtra(EXTRA_USER_ACCOUNT_OPTIONS, accountOptions); 162112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 162212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani return intent; 162312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 162412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 162512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 162612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 162712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * 1628d86b8fea43ebb6e5c31691b44d8ceb0d8d3c9072Jeff Sharkey * Returns the preferred account name for user creation. 162912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 163012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani @SystemApi 1631d86b8fea43ebb6e5c31691b44d8ceb0d8d3c9072Jeff Sharkey @RequiresPermission(android.Manifest.permission.MANAGE_USERS) 163212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public String getSeedAccountName() { 163312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani try { 163412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani return mService.getSeedAccountName(); 163512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } catch (RemoteException re) { 1636f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 163712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 163812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 163912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 164012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 164112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 164212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * 1643d86b8fea43ebb6e5c31691b44d8ceb0d8d3c9072Jeff Sharkey * Returns the preferred account type for user creation. 164412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 164512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani @SystemApi 1646d86b8fea43ebb6e5c31691b44d8ceb0d8d3c9072Jeff Sharkey @RequiresPermission(android.Manifest.permission.MANAGE_USERS) 164712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public String getSeedAccountType() { 164812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani try { 164912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani return mService.getSeedAccountType(); 165012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } catch (RemoteException re) { 1651f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 165212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 165312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 165412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 165512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 165612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 165712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * 1658d86b8fea43ebb6e5c31691b44d8ceb0d8d3c9072Jeff Sharkey * Returns the preferred account's options bundle for user creation. 165912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @return Any options set by the requestor that created the user. 166012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 166112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani @SystemApi 1662d86b8fea43ebb6e5c31691b44d8ceb0d8d3c9072Jeff Sharkey @RequiresPermission(android.Manifest.permission.MANAGE_USERS) 166312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public PersistableBundle getSeedAccountOptions() { 166412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani try { 166512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani return mService.getSeedAccountOptions(); 166612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } catch (RemoteException re) { 1667f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 166812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 166912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 167012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 167112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 167212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 167312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * 167412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Called by a system activity to set the seed account information of a user created 167512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * through the user creation intent. 167612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param userId 167712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param accountName 167812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param accountType 167912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param accountOptions 168012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @see #createUserCreationIntent(String, String, String, PersistableBundle) 168112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 168212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public void setSeedAccountData(int userId, String accountName, String accountType, 168312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani PersistableBundle accountOptions) { 168412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani try { 168512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani mService.setSeedAccountData(userId, accountName, accountType, accountOptions, 168612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /* persist= */ true); 168712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } catch (RemoteException re) { 1688f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 168912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 169012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 169112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 169212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 169312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 1694d86b8fea43ebb6e5c31691b44d8ceb0d8d3c9072Jeff Sharkey * Clears the seed information used to create this user. 169512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 169612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani @SystemApi 1697d86b8fea43ebb6e5c31691b44d8ceb0d8d3c9072Jeff Sharkey @RequiresPermission(android.Manifest.permission.MANAGE_USERS) 169812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public void clearSeedAccountData() { 169912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani try { 170012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani mService.clearSeedAccountData(); 170112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } catch (RemoteException re) { 1702f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 170312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 170412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 170512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 170612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 17071df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani * @hide 17081df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani * Marks the guest user for deletion to allow a new guest to be created before deleting 17091df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani * the current user who is a guest. 17101df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani * @param userHandle 17111df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani * @return 17121df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani */ 17138588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean markGuestForDeletion(@UserIdInt int userHandle) { 17141df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani try { 17151df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani return mService.markGuestForDeletion(userHandle); 17161df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani } catch (RemoteException re) { 1717f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 17181df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani } 17191df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani } 17201df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani 17211df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani /** 1722df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina * Sets the user as enabled, if such an user exists. 17231ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova * 17241ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 17251ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova * 17261ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova * <p>Note that the default is true, it's only that managed profiles might not be enabled. 17271ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova * Also ephemeral users can be disabled to indicate that their removal is in progress and they 17281ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova * shouldn't be re-entered. Therefore ephemeral users should not be re-enabled once disabled. 1729df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina * 1730df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina * @param userHandle the id of the profile to enable 1731df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina * @hide 1732df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina */ 17338588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public void setUserEnabled(@UserIdInt int userHandle) { 1734df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina try { 1735df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina mService.setUserEnabled(userHandle); 173627b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 1737f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1738df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina } 1739df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina } 1740df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina 1741df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina /** 174285a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull * Evicts the user's credential encryption key from memory by stopping and restarting the user. 174385a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull * 174485a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull * @hide 174585a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull */ 174685a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull public void evictCredentialEncryptionKey(@UserIdInt int userHandle) { 174785a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull try { 174885a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull mService.evictCredentialEncryptionKey(userHandle); 174985a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull } catch (RemoteException re) { 175085a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull throw re.rethrowFromSystemServer(); 175185a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull } 175285a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull } 175385a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull 175485a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull /** 1755b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * Return the number of users currently created on the device. 1756b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn */ 1757b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn public int getUserCount() { 1758b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn List<UserInfo> users = getUsers(); 1759b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn return users != null ? users.size() : 1; 1760b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn } 1761b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn 1762b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn /** 1763d04aaa323c3a788d26f18fc66e0a59b47e525b38Amith Yamasani * Returns information for all users on this device, including ones marked for deletion. 1764d04aaa323c3a788d26f18fc66e0a59b47e525b38Amith Yamasani * To retrieve only users that are alive, use {@link #getUsers(boolean)}. 1765d04aaa323c3a788d26f18fc66e0a59b47e525b38Amith Yamasani * <p> 17661952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1767940e8577a1569140521fb605336997863529f7adFyodor Kupolov * @return the list of users that exist on the device. 1768258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1769258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 1770258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public List<UserInfo> getUsers() { 1771258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 1772920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani return mService.getUsers(false); 1773920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani } catch (RemoteException re) { 1774f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1775920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani } 1776920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani } 1777920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani 1778920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani /** 1779940e8577a1569140521fb605336997863529f7adFyodor Kupolov * Returns serial numbers of all users on this device. 1780940e8577a1569140521fb605336997863529f7adFyodor Kupolov * 1781940e8577a1569140521fb605336997863529f7adFyodor Kupolov * @param excludeDying specify if the list should exclude users being removed. 1782940e8577a1569140521fb605336997863529f7adFyodor Kupolov * @return the list of serial numbers of users that exist on the device. 1783940e8577a1569140521fb605336997863529f7adFyodor Kupolov * @hide 1784940e8577a1569140521fb605336997863529f7adFyodor Kupolov */ 1785940e8577a1569140521fb605336997863529f7adFyodor Kupolov @SystemApi 1786d86b8fea43ebb6e5c31691b44d8ceb0d8d3c9072Jeff Sharkey @RequiresPermission(android.Manifest.permission.MANAGE_USERS) 1787940e8577a1569140521fb605336997863529f7adFyodor Kupolov public long[] getSerialNumbersOfUsers(boolean excludeDying) { 1788940e8577a1569140521fb605336997863529f7adFyodor Kupolov try { 1789940e8577a1569140521fb605336997863529f7adFyodor Kupolov List<UserInfo> users = mService.getUsers(excludeDying); 1790940e8577a1569140521fb605336997863529f7adFyodor Kupolov long[] result = new long[users.size()]; 1791940e8577a1569140521fb605336997863529f7adFyodor Kupolov for (int i = 0; i < result.length; i++) { 1792940e8577a1569140521fb605336997863529f7adFyodor Kupolov result[i] = users.get(i).serialNumber; 1793940e8577a1569140521fb605336997863529f7adFyodor Kupolov } 1794940e8577a1569140521fb605336997863529f7adFyodor Kupolov return result; 1795940e8577a1569140521fb605336997863529f7adFyodor Kupolov } catch (RemoteException re) { 1796f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1797940e8577a1569140521fb605336997863529f7adFyodor Kupolov } 1798940e8577a1569140521fb605336997863529f7adFyodor Kupolov } 1799940e8577a1569140521fb605336997863529f7adFyodor Kupolov 1800940e8577a1569140521fb605336997863529f7adFyodor Kupolov /** 1801b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen * @return the user's account name, null if not found. 1802b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen * @hide 1803b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen */ 1804b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen @RequiresPermission( allOf = { 1805b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen Manifest.permission.INTERACT_ACROSS_USERS_FULL, 1806b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen Manifest.permission.MANAGE_USERS 1807b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen }) 18088588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public @Nullable String getUserAccount(@UserIdInt int userHandle) { 1809b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen try { 1810b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen return mService.getUserAccount(userHandle); 1811b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen } catch (RemoteException re) { 1812f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1813b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen } 1814b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen } 1815b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen 1816b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen /** 1817b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen * Set account name for the given user. 1818b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen * @hide 1819b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen */ 1820b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen @RequiresPermission( allOf = { 1821b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen Manifest.permission.INTERACT_ACROSS_USERS_FULL, 1822b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen Manifest.permission.MANAGE_USERS 1823b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen }) 18248588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public void setUserAccount(@UserIdInt int userHandle, @Nullable String accountName) { 1825b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen try { 1826b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen mService.setUserAccount(userHandle, accountName); 1827b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen } catch (RemoteException re) { 1828f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1829b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen } 1830b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen } 1831b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen 1832b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen /** 183370f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * Returns information for Primary user. 183470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 183570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * 183670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * @return the Primary user, null if not found. 183770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * @hide 183870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen */ 18397cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen public @Nullable UserInfo getPrimaryUser() { 184070f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen try { 184170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen return mService.getPrimaryUser(); 184270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen } catch (RemoteException re) { 1843f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 184470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen } 184570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen } 184670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen 184770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen /** 184895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS 184995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani * permission. 185095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani * 185195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani * @return true if more users can be added, false if limit has been reached. 185295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani * @hide 185395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani */ 185495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani public boolean canAddMoreUsers() { 185595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani final List<UserInfo> users = getUsers(true); 185695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani final int totalUserCount = users.size(); 185795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani int aliveUserCount = 0; 185895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani for (int i = 0; i < totalUserCount; i++) { 185995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani UserInfo user = users.get(i); 186095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani if (!user.isGuest()) { 186195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani aliveUserCount++; 186295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani } 186395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani } 186495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani return aliveUserCount < getMaxSupportedUsers(); 186595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani } 186695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani 186795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani /** 186872434b7088591828082dd952496d523ef3622de2Nicolas Prevot * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS 186972434b7088591828082dd952496d523ef3622de2Nicolas Prevot * permission. 187007387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot * if allowedToRemoveOne is true and if the user already has a managed profile, then return if 187107387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot * we could add a new managed profile to this user after removing the existing one. 187272434b7088591828082dd952496d523ef3622de2Nicolas Prevot * 187372434b7088591828082dd952496d523ef3622de2Nicolas Prevot * @return true if more managed profiles can be added, false if limit has been reached. 187472434b7088591828082dd952496d523ef3622de2Nicolas Prevot * @hide 187572434b7088591828082dd952496d523ef3622de2Nicolas Prevot */ 18768588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean canAddMoreManagedProfiles(@UserIdInt int userId, boolean allowedToRemoveOne) { 187772434b7088591828082dd952496d523ef3622de2Nicolas Prevot try { 187807387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot return mService.canAddMoreManagedProfiles(userId, allowedToRemoveOne); 187972434b7088591828082dd952496d523ef3622de2Nicolas Prevot } catch (RemoteException re) { 1880f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 188172434b7088591828082dd952496d523ef3622de2Nicolas Prevot } 188272434b7088591828082dd952496d523ef3622de2Nicolas Prevot } 188372434b7088591828082dd952496d523ef3622de2Nicolas Prevot 188472434b7088591828082dd952496d523ef3622de2Nicolas Prevot /** 18852a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * Returns list of the profiles of userHandle including 18862a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * userHandle itself. 18874f7e2e334e4ca5f1a67baf4bdd40cd080b954161Amith Yamasani * Note that this returns both enabled and not enabled profiles. See 18887f75da2405cd910854448bb3801f776e036f926aRuben Brunk * {@link #getEnabledProfiles(int)} if you need only the enabled ones. 18894f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * 18902a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 18912a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * @param userHandle profiles of this user will be returned. 18922a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * @return the list of profiles. 18932a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * @hide 18942a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy */ 18958588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public List<UserInfo> getProfiles(@UserIdInt int userHandle) { 1896a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy try { 1897385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina return mService.getProfiles(userHandle, false /* enabledOnly */); 1898a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } catch (RemoteException re) { 1899f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1900a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } 1901a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } 1902a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy 1903a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy /** 1904fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1905fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen * @param userId one of the two user ids to check. 1906fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen * @param otherUserId one of the two user ids to check. 1907fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen * @return true if the two user ids are in the same profile group. 1908fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen * @hide 1909fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen */ 19108588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean isSameProfileGroup(@UserIdInt int userId, int otherUserId) { 1911fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen try { 1912fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen return mService.isSameProfileGroup(userId, otherUserId); 1913fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen } catch (RemoteException re) { 1914f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1915fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen } 1916fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen } 1917fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen 1918fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen /** 19197f75da2405cd910854448bb3801f776e036f926aRuben Brunk * Returns list of the profiles of userHandle including 19207f75da2405cd910854448bb3801f776e036f926aRuben Brunk * userHandle itself. 19217f75da2405cd910854448bb3801f776e036f926aRuben Brunk * Note that this returns only enabled. 19227f75da2405cd910854448bb3801f776e036f926aRuben Brunk * 19237f75da2405cd910854448bb3801f776e036f926aRuben Brunk * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 19247f75da2405cd910854448bb3801f776e036f926aRuben Brunk * @param userHandle profiles of this user will be returned. 19257f75da2405cd910854448bb3801f776e036f926aRuben Brunk * @return the list of profiles. 19267f75da2405cd910854448bb3801f776e036f926aRuben Brunk * @hide 19277f75da2405cd910854448bb3801f776e036f926aRuben Brunk */ 19288588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public List<UserInfo> getEnabledProfiles(@UserIdInt int userHandle) { 19297f75da2405cd910854448bb3801f776e036f926aRuben Brunk try { 19307f75da2405cd910854448bb3801f776e036f926aRuben Brunk return mService.getProfiles(userHandle, true /* enabledOnly */); 19317f75da2405cd910854448bb3801f776e036f926aRuben Brunk } catch (RemoteException re) { 1932f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 19337f75da2405cd910854448bb3801f776e036f926aRuben Brunk } 19347f75da2405cd910854448bb3801f776e036f926aRuben Brunk } 19357f75da2405cd910854448bb3801f776e036f926aRuben Brunk 19367f75da2405cd910854448bb3801f776e036f926aRuben Brunk /** 1937be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * Returns a list of UserHandles for profiles associated with the user that the calling process 1938be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * is running on, including the user itself. 19394f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * 19404f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * @return A non-empty list of UserHandles associated with the calling user. 19414f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani */ 19424f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani public List<UserHandle> getUserProfiles() { 19437f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov int[] userIds = getProfileIds(UserHandle.myUserId(), true /* enabledOnly */); 19447f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov List<UserHandle> result = new ArrayList<>(userIds.length); 19457f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov for (int userId : userIds) { 19467f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov result.add(UserHandle.of(userId)); 19477f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov } 19487f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov return result; 19497f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov } 19507f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov 19517f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov /** 19527f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * Returns a list of ids for profiles associated with the specified user including the user 19537f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * itself. 19547f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * 19557f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * @param userId id of the user to return profiles for 19567f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * @param enabledOnly whether return only {@link UserInfo#isEnabled() enabled} profiles 19577f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * @return A non-empty list of ids of profiles associated with the specified user. 19587f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * 19597f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * @hide 19607f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov */ 19617f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov public int[] getProfileIds(@UserIdInt int userId, boolean enabledOnly) { 1962385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina try { 19637f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov return mService.getProfileIds(userId, enabledOnly); 1964385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina } catch (RemoteException re) { 1965f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1966385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina } 19677f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov } 19687f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov 19697f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov /** 19707f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * @see #getProfileIds(int, boolean) 19717f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * @hide 19727f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov */ 19737f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov public int[] getProfileIdsWithDisabled(@UserIdInt int userId) { 19747f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov return getProfileIds(userId, false /* enabledOnly */); 19757f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov } 19767f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov 19777f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov /** 19787f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * @see #getProfileIds(int, boolean) 19797f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * @hide 19807f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov */ 19817f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov public int[] getEnabledProfileIds(@UserIdInt int userId) { 19827f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov return getProfileIds(userId, true /* enabledOnly */); 19834f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani } 19844f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani 19857dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani /** 1986c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales * Returns the device credential owner id of the profile from 1987c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales * which this method is called, or userHandle if called from a user that 1988c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales * is not a profile. 1989c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales * 1990c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales * @hide 1991c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales */ 19928588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public int getCredentialOwnerProfile(@UserIdInt int userHandle) { 1993c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales try { 1994c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales return mService.getCredentialOwnerProfile(userHandle); 1995c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales } catch (RemoteException re) { 1996f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1997c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales } 1998c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales } 1999c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales 2000c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales /** 2001be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * Returns the parent of the profile which this method is called from 2002be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * or null if called from a user that is not a profile. 2003be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * 2004be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * @hide 2005be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel */ 20068588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public UserInfo getProfileParent(@UserIdInt int userHandle) { 2007be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel try { 2008be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel return mService.getProfileParent(userHandle); 2009be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel } catch (RemoteException re) { 2010f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 2011be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel } 2012be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel } 2013be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel 2014be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel /** 20150a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * Set quiet mode of a managed profile. 20160a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * 20170a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * @param userHandle The user handle of the profile. 20180a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * @param enableQuietMode Whether quiet mode should be enabled or disabled. 20190a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * @hide 20200a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu */ 20218588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public void setQuietModeEnabled(@UserIdInt int userHandle, boolean enableQuietMode) { 20220a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu try { 20230a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu mService.setQuietModeEnabled(userHandle, enableQuietMode); 202427b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 2025f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 20260a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu } 20270a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu } 20280a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu 20290a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu /** 20300a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * Returns whether the given profile is in quiet mode or not. 20317881cf8f818317cc6efe4d6a4c42da94d6bab223Ricky Wai * Notes: Quiet mode is only supported for managed profiles. 20320a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * 20330a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * @param userHandle The user handle of the profile to be queried. 20340a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * @return true if the profile is in quiet mode, false otherwise. 20350a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu */ 20360a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu public boolean isQuietModeEnabled(UserHandle userHandle) { 20370a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu try { 20380a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu return mService.isQuietModeEnabled(userHandle.getIdentifier()); 203927b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 2040f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 20410a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu } 20420a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu } 20430a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu 20440a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu /** 2045f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz * Tries disabling quiet mode for a given user. If the user is still locked, we unlock the user 2046f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz * first by showing the confirm credentials screen and disable quiet mode upon successful 2047f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz * unlocking. If the user is already unlocked, we call through to {@link #setQuietModeEnabled} 2048f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz * directly. 2049f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz * 2050f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz * @return true if the quiet mode was disabled immediately 2051f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz * @hide 2052f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz */ 2053f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz public boolean trySetQuietModeDisabled(@UserIdInt int userHandle, IntentSender target) { 2054f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz try { 2055f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz return mService.trySetQuietModeDisabled(userHandle, target); 2056f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz } catch (RemoteException re) { 2057f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz throw re.rethrowFromSystemServer(); 2058f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz } 2059f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz } 2060f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz 2061f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz /** 20627dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani * If the target user is a managed profile of the calling user or the caller 20637dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani * is itself a managed profile, then this returns a badged copy of the given 2064c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * icon to be able to distinguish it from the original icon. For badging an 2065c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * arbitrary drawable use {@link #getBadgedDrawableForUser( 2066c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}. 2067c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * <p> 2068c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * If the original drawable is a BitmapDrawable and the backing bitmap is 206966ae66a7f74ee835807a141a216afbb254664510Vadim Tryshev * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging 2070c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * is performed in place and the original drawable is returned. 2071c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * </p> 2072c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * 2073c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param icon The icon to badge. 2074c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param user The target user. 2075c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @return A drawable that combines the original icon and a badge as 2076c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * determined by the system. 2077c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav * @removed 2078c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav */ 2079c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) { 2080c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav return mContext.getPackageManager().getUserBadgedIcon(icon, user); 2081c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav } 2082c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav 2083c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav /** 2084c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * If the target user is a managed profile of the calling user or the caller 2085c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * is itself a managed profile, then this returns a badged copy of the given 2086c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * drawable allowing the user to distinguish it from the original drawable. 2087c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * The caller can specify the location in the bounds of the drawable to be 2088c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * badged where the badge should be applied as well as the density of the 2089c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * badge to be used. 2090c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * <p> 2091c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * If the original drawable is a BitmapDrawable and the backing bitmap is 209266ae66a7f74ee835807a141a216afbb254664510Vadim Tryshev * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging 2093c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * is performed in place and the original drawable is returned. 2094c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * </p> 2095c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * 2096c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param badgedDrawable The drawable to badge. 2097c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param user The target user. 2098c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param badgeLocation Where in the bounds of the badged drawable to place 209966ae66a7f74ee835807a141a216afbb254664510Vadim Tryshev * the badge. If it's {@code null}, the badge is applied on top of the entire 2100c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * drawable being badged. 2101c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param badgeDensity The optional desired density for the badge as per 210266ae66a7f74ee835807a141a216afbb254664510Vadim Tryshev * {@link android.util.DisplayMetrics#densityDpi}. If it's not positive, 2103c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * the density of the display is used. 2104c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @return A drawable that combines the original drawable and a badge as 2105c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * determined by the system. 2106c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav * @removed 2107c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav */ 2108c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user, 2109c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav Rect badgeLocation, int badgeDensity) { 2110c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user, 2111c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav badgeLocation, badgeDensity); 21124f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani } 21134f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani 2114701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy /** 2115701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy * If the target user is a managed profile of the calling user or the caller 2116f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * is itself a managed profile, then this returns a copy of the label with 2117f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * badging for accessibility services like talkback. E.g. passing in "Email" 2118f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * and it might return "Work Email" for Email in the work profile. 2119f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * 2120f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * @param label The label to change. 2121f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * @param user The target user. 2122f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * @return A label that combines the original label and a badge as 2123f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * determined by the system. 2124c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav * @removed 2125f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy */ 2126237aecd18d0edf56c038761f570758c310c9e6dfKenny Guy public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) { 2127c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav return mContext.getPackageManager().getUserBadgedLabel(label, user); 21284f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani } 21294f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani 21304f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani /** 21314f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * Returns information for all users on this device. Requires 21324f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * {@link android.Manifest.permission#MANAGE_USERS} permission. 2133394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier * 21344f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * @param excludeDying specify if the list should exclude users being 21354f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * removed. 2136920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani * @return the list of users that were created. 2137920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani * @hide 2138920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani */ 2139ada8deb43649aed879ceba28daee4af69ae0cc8dAdam Lesinski public @NonNull List<UserInfo> getUsers(boolean excludeDying) { 2140920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani try { 2141920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani return mService.getUsers(excludeDying); 2142258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 2143f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 2144258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 2145258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 2146258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 2147258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 2148258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Removes a user and all associated data. 21491952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 2150258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the integer handle of the user, where 0 is the primary user. 2151258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 2152258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 21538588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean removeUser(@UserIdInt int userHandle) { 2154258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 2155258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.removeUser(userHandle); 2156258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 2157f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 2158258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 2159258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 2160258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 2161258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 2162d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot * Similar to {@link #removeUser(int)} except bypassing the checking of 2163d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot * {@link UserManager#DISALLOW_REMOVE_USER} 2164d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot * or {@link UserManager#DISALLOW_REMOVE_MANAGED_PROFILE}. 2165d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot * 2166d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot * @see {@link #removeUser(int)} 2167d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot * @hide 2168d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot */ 2169d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot public boolean removeUserEvenWhenDisallowed(@UserIdInt int userHandle) { 2170d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot try { 2171d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot return mService.removeUserEvenWhenDisallowed(userHandle); 2172d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot } catch (RemoteException re) { 2173d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot throw re.rethrowFromSystemServer(); 2174d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot } 2175d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot } 2176d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot 2177d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot /** 2178258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Updates the user's name. 21791952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 2180258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 2181258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the user's integer handle 2182258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param name the new name for the user 2183258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 2184258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 21858588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public void setUserName(@UserIdInt int userHandle, String name) { 2186258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 2187258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mService.setUserName(userHandle, name); 2188258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 2189f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 2190258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 2191258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 2192258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 2193258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 2194e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * Sets the user's photo. 2195258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the user for whom to change the photo. 2196e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * @param icon the bitmap to set as the photo. 2197258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 2198258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 21998588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public void setUserIcon(@UserIdInt int userHandle, Bitmap icon) { 2200258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 2201e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani mService.setUserIcon(userHandle, icon); 2202258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 2203f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 2204258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 2205258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 2206258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 2207258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 22083b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani * Returns a file descriptor for the user's photo. PNG data can be read from this file. 22093b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani * @param userHandle the user whose photo we want to read. 2210e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * @return a {@link Bitmap} of the user's photo, or null if there's no photo. 221164d4dca63f65e4c7d4a829c85ff6670bdd34e2ebAlexandra Gherghina * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default. 22123b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani * @hide 22133b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani */ 22148588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public Bitmap getUserIcon(@UserIdInt int userHandle) { 22153b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani try { 22161bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos ParcelFileDescriptor fd = mService.getUserIcon(userHandle); 22171bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos if (fd != null) { 22181bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos try { 22191bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor()); 22201bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos } finally { 22211bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos try { 22221bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos fd.close(); 22231bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos } catch (IOException e) { 22241bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos } 22251bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos } 22261bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos } 22273b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani } catch (RemoteException re) { 2228f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 22293b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani } 22301bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos return null; 22313b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani } 22323b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani 22333b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani /** 2234258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns the maximum number of users that can be created on this device. A return value 2235258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * of 1 means that it is a single user device. 2236258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 2237a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @return a value greater than or equal to 1 2238258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 223927bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey public static int getMaxSupportedUsers() { 2240ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani // Don't allow multiple users on certain builds 2241ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani if (android.os.Build.ID.startsWith("JVP")) return 1; 2242409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn // Svelte devices don't get multi-user. 2243409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn if (ActivityManager.isLowRamDeviceStatic()) return 1; 224427bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey return SystemProperties.getInt("fw.max_users", 224527bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers)); 2246258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 22472a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani 22482a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani /** 2249cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov * Returns true if the user switcher should be shown, this will be if device supports multi-user 2250cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov * and there are at least 2 users available that are not managed profiles. 22511a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy * @hide 22521a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy * @return true if user switcher should be shown. 22531a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy */ 22541a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy public boolean isUserSwitcherEnabled() { 2255cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov if (!supportsMultipleUsers()) { 2256cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov return false; 2257cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov } 2258eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani // If Demo Mode is on, don't show user switcher 2259eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani if (isDeviceInDemoMode(mContext)) { 2260eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani return false; 2261eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani } 22621a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy List<UserInfo> users = getUsers(true); 22631a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy if (users == null) { 22641a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy return false; 22651a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy } 22661a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy int switchableUserCount = 0; 22671a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy for (UserInfo user : users) { 22687cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen if (user.supportsSwitchToByUser()) { 22691a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy ++switchableUserCount; 22701a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy } 22711a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy } 2272cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class) 2273cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov .getGuestUserDisabled(null); 2274a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani return switchableUserCount > 1 || guestEnabled; 22751a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy } 22761a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy 22771a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy /** 2278eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani * @hide 2279eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani */ 2280eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani public static boolean isDeviceInDemoMode(Context context) { 2281eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani return Settings.Global.getInt(context.getContentResolver(), 2282eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani Settings.Global.DEVICE_DEMO_MODE, 0) > 0; 2283eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani } 2284eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani 2285eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani /** 22862a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * Returns a serial number on this device for a given userHandle. User handles can be recycled 22872a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * when deleting and creating users, but serial numbers are not reused until the device is wiped. 22882a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @param userHandle 22892a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @return a serial number associated with that user, or -1 if the userHandle is not valid. 22902a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @hide 22912a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani */ 22928588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public int getUserSerialNumber(@UserIdInt int userHandle) { 22932a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani try { 22942a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani return mService.getUserSerialNumber(userHandle); 22952a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } catch (RemoteException re) { 2296f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 22972a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 22982a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 22992a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani 23002a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani /** 23012a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * Returns a userHandle on this device for a given user serial number. User handles can be 23022a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * recycled when deleting and creating users, but serial numbers are not reused until the device 23032a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * is wiped. 23042a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @param userSerialNumber 23052a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @return the userHandle associated with that user serial number, or -1 if the serial number 23062a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * is not valid. 23072a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @hide 23082a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani */ 23098588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public @UserIdInt int getUserHandle(int userSerialNumber) { 23102a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani try { 23112a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani return mService.getUserHandle(userSerialNumber); 23122a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } catch (RemoteException re) { 2313f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 23142a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 23152a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 23166794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 23177e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani /** 2318953fe483298bff46558a4e0b2d891924c0c9c813Esteban Talavera * Returns a {@link Bundle} containing any saved application restrictions for this user, for the 23197e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani * given package name. Only an application with this package name can call this method. 23205b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * 23215b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * <p>The returned {@link Bundle} consists of key-value pairs, as defined by the application, 23225b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * where the types of values may be: 23235b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * <ul> 23245b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * <li>{@code boolean} 23255b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * <li>{@code int} 23265b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * <li>{@code String} or {@code String[]} 23275b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} 23285b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * </ul> 23295b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * 23304e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolov * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread 23314e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolov * 23327e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani * @param packageName the package name of the calling application 2333953fe483298bff46558a4e0b2d891924c0c9c813Esteban Talavera * @return a {@link Bundle} with the restrictions for that package, or an empty {@link Bundle} 2334953fe483298bff46558a4e0b2d891924c0c9c813Esteban Talavera * if there are no saved restrictions. 23355b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * 23365b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * @see #KEY_RESTRICTIONS_PENDING 23377e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani */ 23384e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolov @WorkerThread 23397e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani public Bundle getApplicationRestrictions(String packageName) { 23407e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani try { 23417e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani return mService.getApplicationRestrictions(packageName); 23427e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani } catch (RemoteException re) { 2343f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 23447e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani } 23457e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani } 2346df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 2347df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani /** 2348df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * @hide 2349df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani */ 23504e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolov @WorkerThread 23517e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani public Bundle getApplicationRestrictions(String packageName, UserHandle user) { 2352df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani try { 23537e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier()); 2354df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } catch (RemoteException re) { 2355f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 2356df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 2357df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 2358df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 2359df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani /** 2360df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * @hide 2361df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani */ 23624e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolov @WorkerThread 23637e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani public void setApplicationRestrictions(String packageName, Bundle restrictions, 2364df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani UserHandle user) { 2365df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani try { 23667e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier()); 2367df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } catch (RemoteException re) { 2368f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 2369df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 2370df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 2371655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani 2372655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** 2373d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * Sets a new challenge PIN for restrictions. This is only for use by pre-installed 2374d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * apps and requires the MANAGE_USERS permission. 2375d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * @param newPin the PIN to use for challenge dialogs. 2376d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * @return Returns true if the challenge PIN was set successfully. 2377ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov * @deprecated The restrictions PIN functionality is no longer provided by the system. 2378ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov * This method is preserved for backwards compatibility reasons and always returns false. 2379655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani */ 2380514c5ef8d5774d8820ed1bf90fe53af1606cf106Aurimas Liutikas @Deprecated 2381d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani public boolean setRestrictionsChallenge(String newPin) { 2382655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani return false; 2383655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani } 23841a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani 2385e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani /** 2386e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani * @hide 2387e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani * Set restrictions that should apply to any future guest user that's created. 2388e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani */ 2389e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani public void setDefaultGuestRestrictions(Bundle restrictions) { 2390e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani try { 2391e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani mService.setDefaultGuestRestrictions(restrictions); 2392e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } catch (RemoteException re) { 2393f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 2394e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } 2395e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } 2396e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani 2397e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani /** 2398e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani * @hide 2399e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani * Gets the default guest restrictions. 2400e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani */ 2401e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani public Bundle getDefaultGuestRestrictions() { 2402e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani try { 2403e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani return mService.getDefaultGuestRestrictions(); 2404e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } catch (RemoteException re) { 2405f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 2406e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } 2407e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } 2408ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov 2409ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov /** 2410ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov * Returns creation time of the user or of a managed profile associated with the calling user. 2411ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov * @param userHandle user handle of the user or a managed profile associated with the 2412ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov * calling user. 2413ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov * @return creation time in milliseconds since Epoch time. 2414ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov */ 2415385de624aa990266ffbaf70711ac8a330569429eFyodor Kupolov public long getUserCreationTime(UserHandle userHandle) { 2416ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov try { 2417385de624aa990266ffbaf70711ac8a330569429eFyodor Kupolov return mService.getUserCreationTime(userHandle.getIdentifier()); 2418ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov } catch (RemoteException re) { 2419f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 2420ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov } 2421ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov } 242212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 242312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 242412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 242512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Checks if any uninitialized user has the specific seed account name and type. 242612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * 24276a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * @param accountName The account name to check for 24286a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * @param accountType The account type of the account to check for 242912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @return whether the seed account was found 243012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 243112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public boolean someUserHasSeedAccount(String accountName, String accountType) { 243212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani try { 243312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani return mService.someUserHasSeedAccount(accountName, accountType); 243412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } catch (RemoteException re) { 2435f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 243612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 243712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 24386a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov 24396a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov /** 24406a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * @hide 24416a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * User that enforces a restriction. 24426a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * 24436a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * @see #getUserRestrictionSources(String, UserHandle) 24446a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov */ 24456a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov @SystemApi 24466a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov public static final class EnforcingUser implements Parcelable { 24476a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov private final @UserIdInt int userId; 24486a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov private final @UserRestrictionSource int userRestrictionSource; 24496a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov 24506a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov /** 24516a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * @hide 24526a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov */ 24536a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov public EnforcingUser( 24546a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov @UserIdInt int userId, @UserRestrictionSource int userRestrictionSource) { 24556a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov this.userId = userId; 24566a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov this.userRestrictionSource = userRestrictionSource; 24576a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov } 24586a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov 24596a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov private EnforcingUser(Parcel in) { 24606a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov userId = in.readInt(); 24616a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov userRestrictionSource = in.readInt(); 24626a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov } 24636a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov 24646a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov public static final Creator<EnforcingUser> CREATOR = new Creator<EnforcingUser>() { 24656a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov @Override 24666a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov public EnforcingUser createFromParcel(Parcel in) { 24676a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov return new EnforcingUser(in); 24686a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov } 24696a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov 24706a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov @Override 24716a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov public EnforcingUser[] newArray(int size) { 24726a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov return new EnforcingUser[size]; 24736a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov } 24746a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov }; 24756a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov 24766a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov @Override 24776a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov public int describeContents() { 24786a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov return 0; 24796a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov } 24806a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov 24816a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov @Override 24826a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov public void writeToParcel(Parcel dest, int flags) { 24836a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov dest.writeInt(userId); 24846a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov dest.writeInt(userRestrictionSource); 24856a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov } 24866a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov 24876a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov /** 24886a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * Returns an id of the enforcing user. 24896a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * 24906a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * <p> Will be UserHandle.USER_NULL when restriction is set by the system. 24916a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov */ 24926a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov public UserHandle getUserHandle() { 24936a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov return UserHandle.of(userId); 24946a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov } 24956a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov 24966a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov /** 24976a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * Returns the status of the enforcing user. 24986a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * 24996a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * <p> One of {@link #RESTRICTION_SOURCE_SYSTEM}, 25006a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * {@link #RESTRICTION_SOURCE_DEVICE_OWNER} and 25016a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov * {@link #RESTRICTION_SOURCE_PROFILE_OWNER} 25026a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov */ 25036a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov public @UserRestrictionSource int getUserRestrictionSource() { 25046a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov return userRestrictionSource; 25056a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov } 25066a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov } 2507258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani} 2508