UserManager.java revision 4e9af0657615e52c0cd5eebe34a277e197876bc5
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; 227cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chenimport android.annotation.Nullable; 23b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chenimport android.annotation.RequiresPermission; 240e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasaniimport android.annotation.SystemApi; 258588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkeyimport android.annotation.UserIdInt; 264e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolovimport android.annotation.WorkerThread; 2737ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasaniimport android.app.Activity; 28409297da182267465adbc21cfb75a23e8d678117Dianne Hackbornimport android.app.ActivityManager; 29a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackbornimport android.app.ActivityManagerNative; 30cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolovimport android.app.admin.DevicePolicyManager; 31068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onukiimport android.content.ComponentName; 32258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.Context; 3312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasaniimport android.content.Intent; 34f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franzimport android.content.IntentSender; 35258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.pm.UserInfo; 3627bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkeyimport android.content.res.Resources; 376794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport android.graphics.Bitmap; 381bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roosimport android.graphics.BitmapFactory; 394f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.Rect; 404f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.drawable.Drawable; 411e9c21871e81642669079cd290ef47818a3165bdAmith Yamasaniimport android.provider.Settings; 42523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolovimport android.telephony.TelephonyManager; 431c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monkimport android.view.WindowManager.LayoutParams; 44258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 456794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport com.android.internal.R; 466794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 471bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roosimport java.io.IOException; 48e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Banimport java.lang.annotation.Retention; 49e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Banimport java.lang.annotation.RetentionPolicy; 504f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport java.util.ArrayList; 51258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport java.util.List; 52258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 53258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/** 540696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * Manages users and user details on a multi-user system. There are two major categories of 550696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * users: fully customizable users with their own login, and managed profiles that share a workspace 560696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * with a related user. 570696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * <p> 580696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * Users are different from accounts, which are managed by 590696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * {@link AccountManager}. Each user can have their own set of accounts. 600696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * <p> 610696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * See {@link DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE} for more on managed profiles. 62258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 63258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipublic class UserManager { 64258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 65258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani private static String TAG = "UserManager"; 66258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani private final IUserManager mService; 67258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani private final Context mContext; 68258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 69e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 70e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * @hide 71e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * No user restriction. 72e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban */ 73e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban @SystemApi 74e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban public static final int RESTRICTION_NOT_SET = 0x0; 75e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban 76e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban /** 77e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * @hide 78e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * User restriction set by system/user. 79e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban */ 80e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban @SystemApi 81e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban public static final int RESTRICTION_SOURCE_SYSTEM = 0x1; 82e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban 83e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban /** 84e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * @hide 85e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * User restriction set by a device owner. 86e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban */ 87e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban @SystemApi 88e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban public static final int RESTRICTION_SOURCE_DEVICE_OWNER = 0x2; 89e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban 90e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban /** 91e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * @hide 92e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * User restriction set by a profile owner. 93e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban */ 94e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban @SystemApi 95e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban public static final int RESTRICTION_SOURCE_PROFILE_OWNER = 0x4; 96e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban 97e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban /** @hide */ 98e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban @Retention(RetentionPolicy.SOURCE) 99e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban @IntDef(flag=true, value={RESTRICTION_NOT_SET, RESTRICTION_SOURCE_SYSTEM, 100e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban RESTRICTION_SOURCE_DEVICE_OWNER, RESTRICTION_SOURCE_PROFILE_OWNER}) 101e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban @SystemApi 102e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban public @interface UserRestrictionSource {} 103e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban 104e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban /** 10553019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov * Specifies if a user is disallowed from adding and removing accounts, unless they are 10653019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov * {@link android.accounts.AccountManager#addAccountExplicitly programmatically} added by 10753019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov * Authenticator. 10871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 10926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 110b6c0ce4ac915cd5ab9a308cb0a4861c4e2cd7dfbBenjamin Franz * <p>From {@link android.os.Build.VERSION_CODES#N} a profile or device owner app can still 111b6c0ce4ac915cd5ab9a308cb0a4861c4e2cd7dfbBenjamin Franz * use {@link android.accounts.AccountManager} APIs to add or remove accounts when account 112b6c0ce4ac915cd5ab9a308cb0a4861c4e2cd7dfbBenjamin Franz * management is disallowed. 113b6c0ce4ac915cd5ab9a308cb0a4861c4e2cd7dfbBenjamin Franz * 1140ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1150ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 116068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 117068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 118e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 119e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 12071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts"; 121e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 122e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 12326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from changing Wi-Fi 1242cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds * access points. The default value is <code>false</code>. 1250ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect in a managed profile. 12626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 1270ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1280ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 129068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 130068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 131e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 132e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 13371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi"; 134e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 135e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 13626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from installing applications. 13771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 13826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 1390ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1400ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 141068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 142068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 143e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 144e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 14571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_INSTALL_APPS = "no_install_apps"; 146e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 147e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 14826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from uninstalling applications. 14971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 15026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 1510ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1520ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 153068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 154068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 155e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 156e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 15771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps"; 158e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 15971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 160150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * Specifies if a user is disallowed from turning on location sharing. 16171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 1620ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>In a managed profile, location sharing always reflects the primary user's setting, but 163150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * can be overridden and forced off by setting this restriction to true in the managed profile. 16426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 1650ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1660ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 167068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 168068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 1696794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall * @see #getUserRestrictions() 1706794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall */ 17171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_SHARE_LOCATION = "no_share_location"; 1726794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 173a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 17426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from enabling the 175a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * "Unknown Sources" setting, that allows installation of apps from unknown sources. 176a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * The default value is <code>false</code>. 17726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 1780ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1790ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 180068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 181068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 182a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #getUserRestrictions() 183a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 184a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources"; 185a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 186a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 18726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring bluetooth. 1881c4c442e4540b16aed7acc345aea26ab101efbf8Nicolas Prevot * This does <em>not</em> restrict the user from turning bluetooth on or off. 189a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * The default value is <code>false</code>. 1900ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect in a managed profile. 19126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 1920ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1930ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 194068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 195068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 196a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #getUserRestrictions() 197a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 198a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth"; 199a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 200a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 20126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from transferring files over 202c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * USB. This can only be set by device owners and profile owners on the primary user. 203c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 20426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 2050ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 2060ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 207068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 208068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 209a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #getUserRestrictions() 210a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 211a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer"; 212a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 213b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier /** 21426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring user 215b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * credentials. The default value is <code>false</code>. 21626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 2170ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 2180ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 219068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 220068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 221b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * @see #getUserRestrictions() 222b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier */ 223b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials"; 224b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier 225b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier /** 226150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * When set on the primary user this specifies if the user can remove other users. 227150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * When set on a secondary user, this specifies if the user can remove itself. 228150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * This restriction has no effect on managed profiles. 229150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * The default value is <code>false</code>. 23026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 2310ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 2320ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 233068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 234068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 235b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * @see #getUserRestrictions() 236b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier */ 237b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier public static final String DISALLOW_REMOVE_USER = "no_remove_user"; 238b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier 239d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 24026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from enabling or 241d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * accessing debugging features. The default value is <code>false</code>. 24226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 2430ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 2440ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 245068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 246068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 247d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 248d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 249d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features"; 250d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 251d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 25226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring VPN. 253d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * The default value is <code>false</code>. 254298f98fa234f353267ddc9c75d58e8cc542c25f1Nicolas Prevot * This restriction has an effect in a managed profile only from 2550e3de6cacaffcfeda4d6353be61e2f1f9ed80705Dianne Hackborn * {@link android.os.Build.VERSION_CODES#M} 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) 261d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 262d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 263d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_CONFIG_VPN = "no_config_vpn"; 264d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 265d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 26626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring Tethering 267c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * & portable hotspots. This can only be set by device owners and profile owners on the 268c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * primary user. The default value is <code>false</code>. 26926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 2700ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 2710ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 272068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 273068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 274d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 275d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 276d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering"; 277d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 278d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 279e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * Specifies if a user is disallowed from resetting network settings 280e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * from Settings. This can only be set by device owners and profile owners on the primary user. 281e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * The default value is <code>false</code>. 2820ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect on secondary users and managed profiles since only the 283e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * primary user can reset the network settings of the device. 284e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * 2850ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 2860ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 287068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 288068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 289e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * @see #getUserRestrictions() 290e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott */ 291e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott public static final String DISALLOW_NETWORK_RESET = "no_network_reset"; 292e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott 293e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott /** 29426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from factory resetting 295c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * from Settings. This can only be set by device owners and profile owners on the primary user. 296c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 2970ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect on secondary users and managed profiles since only the 298150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * primary user can factory reset the device. 29926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 3000ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 3010ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 302068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 303068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 304d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 305d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 306d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_FACTORY_RESET = "no_factory_reset"; 307d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 308d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 30926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from adding new users and 310c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * profiles. This can only be set by device owners and profile owners on the primary user. 311c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 3120ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect on secondary users and managed profiles since only the 313150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * primary user can add other users. 31426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 3150ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 3160ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 317068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 318068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 319d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 320d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 321d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_ADD_USER = "no_add_user"; 322d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 323d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 32426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from disabling application 325d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * verification. The default value is <code>false</code>. 32626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 3270ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 3280ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 329068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 330068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 331d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 332d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 333d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps"; 334d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 335d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 33626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring cell 337c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * broadcasts. This can only be set by device owners and profile owners on the primary user. 338c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 3390ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect on secondary users and managed profiles since only the 340150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * primary user can configure cell broadcasts. 34126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 3420ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 3430ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 344068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 345068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 346d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 347d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 348d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts"; 349d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 350d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 35126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring mobile 352c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * networks. This can only be set by device owners and profile owners on the primary user. 353c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 3540ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect on secondary users and managed profiles since only the 355150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * primary user can configure mobile networks. 35626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 3570ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 3580ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 359068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 360068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 361d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 362d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 363d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks"; 364d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 365d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 36626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from modifying 367c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * applications in Settings or launchers. The following actions will not be allowed when this 368c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * restriction is enabled: 369c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>uninstalling apps</li> 370c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>disabling apps</li> 371c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>clearing app caches</li> 372c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>clearing app data</li> 373c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>force stopping apps</li> 374c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>clearing app defaults</li> 375c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <p> 376c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * The default value is <code>false</code>. 37726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 3780ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 3790ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 380068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 381068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 382d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 383d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 38436fbc8d6453da438a8ab83352ff1bcfcba5f25b5Julia Reynolds public static final String DISALLOW_APPS_CONTROL = "no_control_apps"; 385d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 386394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier /** 38726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from mounting 388c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * physical external media. This can only be set by device owners and profile owners on the 389c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * primary user. The default value is <code>false</code>. 39026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 3910ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 3920ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 393068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 394068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 395394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier * @see #getUserRestrictions() 396394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier */ 397394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media"; 398394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier 399394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier /** 40026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from adjusting microphone 401c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * volume. If set, the microphone will be muted. This can only be set by device owners 402c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * and profile owners on the primary user. The default value is <code>false</code>. 40326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 4040ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 4050ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 406068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 407068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 408394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier * @see #getUserRestrictions() 409394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier */ 410394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone"; 411394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier 412394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier /** 41326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from adjusting the master 414c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * volume. If set, the master volume will be muted. This can only be set by device owners 415c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * and profile owners on the primary user. The default value is <code>false</code>. 41626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 4170ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 4180ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 419068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 420068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 421394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier * @see #getUserRestrictions() 422394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier */ 423394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume"; 424394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier 4259f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani /** 42626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies that the user is not allowed to make outgoing 427390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani * phone calls. Emergency calls are still permitted. 428390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani * The default value is <code>false</code>. 429eb83ab52b28766adf1743db76484515bc9b9e08aTony Mak * <p>This restriction has no effect on managed profiles. 43026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 4310ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 4320ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 433068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 434068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 435390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani * @see #getUserRestrictions() 436390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani */ 437390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls"; 438390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani 439390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani /** 44026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies that the user is not allowed to send or receive 441c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * SMS messages. The default value is <code>false</code>. 44226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 4430ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 4440ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 445068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 446068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 4479f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani * @see #getUserRestrictions() 4489f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani */ 449390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani public static final String DISALLOW_SMS = "no_sms"; 4509f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani 4511c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk /** 4522cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * Specifies if the user is not allowed to have fun. In some cases, the 4532cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * device owner may wish to prevent the user from experiencing amusement or 4542cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * joy while using the device. The default value is <code>false</code>. 4552cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * 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) 4602cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * @see #getUserRestrictions() 4612cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey */ 4622cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey public static final String DISALLOW_FUN = "no_fun"; 4632cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey 4642cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey /** 46526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies that windows besides app windows should not be 4661c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * created. This will block the creation of the following types of windows. 4671c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_TOAST}</li> 4681c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_PHONE}</li> 4691c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li> 4701c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li> 4711c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li> 4721c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li> 4731c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * 474c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * <p>This can only be set by device owners and profile owners on the primary user. 475c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 47626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 4770ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 4780ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 479068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 480068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 4811c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * @see #getUserRestrictions() 4821c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk */ 4831c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows"; 4841c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk 485f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot /** 48626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if what is copied in the clipboard of this profile can 487f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be 488f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot * pasted in this profile. 489f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot * The default value is <code>false</code>. 49026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 4910ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 4920ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 493068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 494068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 495f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot * @see #getUserRestrictions() 496f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot */ 497f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste"; 498f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot 49926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani /** 50026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if the user is not allowed to use NFC to beam out data from apps. 50126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * The default value is <code>false</code>. 50226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 5030ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 5040ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 505068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 506068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 50726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * @see #getUserRestrictions() 50826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani */ 50926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam"; 51026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani 51153d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse /** 512f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * Hidden user restriction to disallow access to wallpaper manager APIs. This restriction 513f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * generally means that wallpapers are not supported for the particular user. This user 514f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * restriction is always set for managed profiles, because such profiles don't have wallpapers. 515f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz * @hide 516f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * @see #DISALLOW_SET_WALLPAPER 517068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 518068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 519f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz * @see #getUserRestrictions() 520f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz */ 521f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz public static final String DISALLOW_WALLPAPER = "no_wallpaper"; 522f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz 523f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz /** 524f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * User restriction to disallow setting a wallpaper. Profile owner and device owner 525f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * are able to set wallpaper regardless of this restriction. 526f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * The default value is <code>false</code>. 527f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * 528f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * <p>Key for user restrictions. 529f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * <p>Type: Boolean 530f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 531f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 532f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * @see #getUserRestrictions() 533f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi */ 534f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi public static final String DISALLOW_SET_WALLPAPER = "no_set_wallpaper"; 535f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi 536f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi /** 537bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * Specifies if the user is not allowed to reboot the device into safe boot mode. 538bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * This can only be set by device owners and profile owners on the primary user. 539bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * The default value is <code>false</code>. 540bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * 5410ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 5420ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 543068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 544068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 545bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * @see #getUserRestrictions() 546bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz */ 547bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz public static final String DISALLOW_SAFE_BOOT = "no_safe_boot"; 548bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz 549bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz /** 550b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov * Specifies if a user is not allowed to record audio. This restriction is always enabled for 551b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov * background users. The default value is <code>false</code>. 552b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov * 553068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 554068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 555b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov * @see #getUserRestrictions() 556b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov * @hide 557b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov */ 558b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov public static final String DISALLOW_RECORD_AUDIO = "no_record_audio"; 559b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov 560b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov /** 5619cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * Specifies if a user is not allowed to run in the background and should be stopped during 5629cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * user switch. The default value is <code>false</code>. 5639cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * 5649cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * <p>This restriction can be set by device owners and profile owners. 5659cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * 5669cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 5679cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 5689cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * @see #getUserRestrictions() 5699cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * @hide 5709cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov */ 5719cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov public static final String DISALLOW_RUN_IN_BACKGROUND = "no_run_in_background"; 5729cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov 5739cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov /** 574759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * Specifies if a user is not allowed to use the camera. 575759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * 576759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 577759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 578759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * @see #getUserRestrictions() 579759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * @hide 580759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki */ 581759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki public static final String DISALLOW_CAMERA = "no_camera"; 582759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki 583759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki /** 584dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra * Specifies if a user is not allowed to use cellular data when roaming. This can only be set by 585dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra * device owners. The default value is <code>false</code>. 586dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra * 587dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 588dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 589dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra * @see #getUserRestrictions() 590dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra */ 591dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra public static final String DISALLOW_DATA_ROAMING = "no_data_roaming"; 592dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra 593dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra /** 5947f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * Specifies if a user is not allowed to change their icon. Device owner and profile owner 5957f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * can set this restriction. When it is set by device owner, only the target user will be 5967f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * affected. The default value is <code>false</code>. 5977f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * 5987f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * <p>Key for user restrictions. 5997f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * <p>Type: Boolean 6007f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 6017f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 6027f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * @see #getUserRestrictions() 6037f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi */ 6047f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi public static final String DISALLOW_SET_USER_ICON = "no_set_user_icon"; 6057f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi 6067f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi /** 6073d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra * Specifies if a user is not allowed to enable the oem unlock setting. The default value is 6083d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra * <code>false</code>. 6093d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra * 6103d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 6113d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 6123d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra * @see #getUserRestrictions() 6133d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra * @hide 6143d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra */ 6153d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra public static final String DISALLOW_OEM_UNLOCK = "no_oem_unlock"; 6163d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra 6173d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra /** 618f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot * Allows apps in the parent profile to handle web links from the managed profile. 619f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot * 6209edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * This user restriction has an effect only in a managed profile. 6219edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * If set: 6229edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * Intent filters of activities in the parent profile with action 6239edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * {@link android.content.Intent#ACTION_VIEW}, 6249edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which 6259edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * define a host can handle intents from the managed profile. 6269edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * The default value is <code>false</code>. 6279edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * 6280ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 6290ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 630068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 631068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 6329edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * @see #getUserRestrictions() 6339edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot */ 634f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot public static final String ALLOW_PARENT_PROFILE_APP_LINKING 635f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot = "allow_parent_profile_app_linking"; 6369edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot 6379edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot /** 63853d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * Application restriction key that is used to indicate the pending arrival 63953d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * of real restrictions for the app. 64053d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * 64153d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * <p> 64253d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * Applications that support restrictions should check for the presence of this key. 64353d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * A <code>true</code> value indicates that restrictions may be applied in the near 64453d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * future but are not available yet. It is the responsibility of any 64553d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * management application that sets this flag to update it when the final 64653d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * restrictions are enforced. 64753d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * 6480ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for application restrictions. 6490ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 650b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions( 651b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot * android.content.ComponentName, String, Bundle) 652b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions( 653b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot * android.content.ComponentName, String) 65453d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse */ 65553d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending"; 65653d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse 65712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani private static final String ACTION_CREATE_USER = "android.os.action.CREATE_USER"; 65812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 65912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 66012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Extra containing a name for the user being created. Optional parameter passed to 66112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * ACTION_CREATE_USER activity. 66212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 66312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 66412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public static final String EXTRA_USER_NAME = "android.os.extra.USER_NAME"; 66512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 66612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 66712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Extra containing account name for the user being created. Optional parameter passed to 66812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * ACTION_CREATE_USER activity. 66912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 67012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 67112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public static final String EXTRA_USER_ACCOUNT_NAME = "android.os.extra.USER_ACCOUNT_NAME"; 67212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 67312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 67412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Extra containing account type for the user being created. Optional parameter passed to 67512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * ACTION_CREATE_USER activity. 67612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 67712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 67812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public static final String EXTRA_USER_ACCOUNT_TYPE = "android.os.extra.USER_ACCOUNT_TYPE"; 67912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 68012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 68112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Extra containing account-specific data for the user being created. Optional parameter passed 68212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * to ACTION_CREATE_USER activity. 68312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 68412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 68512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public static final String EXTRA_USER_ACCOUNT_OPTIONS 68612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani = "android.os.extra.USER_ACCOUNT_OPTIONS"; 68712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 688655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** @hide */ 689655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3; 690655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** @hide */ 691655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2; 692655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** @hide */ 693655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani public static final int PIN_VERIFICATION_SUCCESS = -1; 694655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani 69537ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani /** 69637ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * Error result indicating that this user is not allowed to add other users on this device. 69737ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * This is a result code returned from the activity created by the intent 69837ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}. 69937ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani */ 70037ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani public static final int USER_CREATION_FAILED_NOT_PERMITTED = Activity.RESULT_FIRST_USER; 70137ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani 70237ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani /** 70337ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * Error result indicating that no more users can be created on this device. 70437ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * This is a result code returned from the activity created by the intent 70537ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}. 70637ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani */ 70737ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani public static final int USER_CREATION_FAILED_NO_MORE_USERS = Activity.RESULT_FIRST_USER + 1; 70837ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani 7097e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani /** @hide */ 710c0688301de5feea94c8456b3b9b42c41d0045f03Amith Yamasani public static UserManager get(Context context) { 711c0688301de5feea94c8456b3b9b42c41d0045f03Amith Yamasani return (UserManager) context.getSystemService(Context.USER_SERVICE); 71227db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani } 713a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 714258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** @hide */ 715258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public UserManager(Context context, IUserManager service) { 716258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mService = service; 717258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mContext = context; 718258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 719258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 720258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 7210696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * Returns whether this device supports multiple users with their own login and customizable 7220696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * space. 7230696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * @return whether the device supports multiple users. 724258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 7254673e7ea8d1f869910a9c0f9c211d4d27ad50b41Jeff Sharkey public static boolean supportsMultipleUsers() { 7261a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy return getMaxSupportedUsers() > 1 7271a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy && SystemProperties.getBoolean("fw.show_multiuserui", 7281a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI)); 729258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 730258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 7316794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall /** 7327cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen * @hide 7337cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen * @return Whether the device is running with split system user. It means the system user and 7347cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen * primary user are two separate users. Previously system user and primary user are combined as 7357cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen * a single owner user. see @link {android.os.UserHandle#USER_OWNER} 7367cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen */ 7377cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen public static boolean isSplitSystemUser() { 7387cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen return SystemProperties.getBoolean("ro.fw.system_user_split", false); 7397cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen } 7407cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen 7417cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen /** 742523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov * Returns whether switching users is currently allowed. 743523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov * <p>For instance switching users is not allowed if the current user is in a phone call, 744523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov * or system user hasn't been unlocked yet 745523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov * @hide 746523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov */ 747523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov public boolean canSwitchUsers() { 748523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov boolean allowUserSwitchingWhenSystemUserLocked = Settings.Global.getInt( 749523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov mContext.getContentResolver(), 750523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0; 751523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM); 752523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov boolean inCall = TelephonyManager.getDefault().getCallState() 753523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov != TelephonyManager.CALL_STATE_IDLE; 754523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall; 755523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov } 756523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov 757523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov /** 7585760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * Returns the user handle for the user that this process is running under. 759be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * 7605760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * @return the user handle of this process. 761258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 7626794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall */ 7638588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public @UserIdInt int getUserHandle() { 76479af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn return UserHandle.myUserId(); 765258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 766258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 767258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 7688832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn * Returns the user name of the user making this call. This call is only 7698832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn * available to applications on the system image; it requires the 7708832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn * MANAGE_USERS permission. 771258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the user name 772258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 773258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public String getUserName() { 774258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 775258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.getUserInfo(getUserHandle()).name; 776258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 777f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 778258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 779258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 780258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 78167a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn /** 782e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill * Used to determine whether the user making this call is subject to 783e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill * teleportations. 78467a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn * 785955d8d69ea6caabce1461dc25b339b9bf9dc61a6Dianne Hackborn * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can 78667a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn * now automatically identify goats using advanced goat recognition technology.</p> 78767a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn * 78867a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn * @return Returns true if the user making this call is a goat. 789e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill */ 790e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill public boolean isUserAGoat() { 791988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell return mContext.getPackageManager() 792988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell .isPackageAvailable("com.coffeestainstudios.goatsimulator"); 793e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill } 794df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 795df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani /** 79670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * Used to check if this process is running under the primary user. The primary user 79770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * is the first human user on a device. 79870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * 79970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * @return whether this process is running under the primary user. 80070f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * @hide 80170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen */ 80270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen public boolean isPrimaryUser() { 80370f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen UserInfo user = getUserInfo(UserHandle.myUserId()); 804d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani return user != null && user.isPrimary(); 80570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen } 80670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen 80770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen /** 8085760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * Used to check if this process is running under the system user. The system user 8095760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * is the initial user that is implicitly created on first boot and hosts most of the 8105760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * system services. 8115760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * 8125760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * @return whether this process is running under the system user. 8135760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani */ 8145760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani public boolean isSystemUser() { 81570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen return UserHandle.myUserId() == UserHandle.USER_SYSTEM; 8165760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani } 8172b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen 8185760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani /** 819462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani * @hide 820462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani * Returns whether the caller is running as an admin user. There can be more than one admin 821462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani * user. 822462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani */ 823462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani public boolean isAdminUser() { 8242b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen return isUserAdmin(UserHandle.myUserId()); 8252b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen } 8262b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen 8272b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen /** 8282b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen * @hide 8292b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen * Returns whether the provided user is an admin user. There can be more than one admin 8302b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen * user. 8312b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen */ 8328588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean isUserAdmin(@UserIdInt int userId) { 8332b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen UserInfo user = getUserInfo(userId); 8342b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen return user != null && user.isAdmin(); 835462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani } 836462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani 837462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani /** 838e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani * Used to check if the user making this call is linked to another user. Linked users may have 83946bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani * a reduced number of available apps, app restrictions and account restrictions. 840e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani * @return whether the user making this call is a linked user 8412555dafce87e60fae28d71913730abf73e40fcd7Amith Yamasani * @hide 842df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani */ 843e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani public boolean isLinkedUser() { 844df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani try { 84571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani return mService.isRestricted(); 846df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } catch (RemoteException re) { 847f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 848df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 849df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 850df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 851258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 8521c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov * Checks if specified user can have restricted profile. 8531c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov * @hide 8541c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov */ 8558588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean canHaveRestrictedProfile(@UserIdInt int userId) { 8561c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov try { 8571c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov return mService.canHaveRestrictedProfile(userId); 8581c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov } catch (RemoteException re) { 859f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 8601c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov } 8611c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov } 8621c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov 8631c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov /** 8641e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * Checks if the calling app is running as a guest user. 8651e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * @return whether the caller is a guest user. 8661e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * @hide 8671e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani */ 8681e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani public boolean isGuestUser() { 8691e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani UserInfo user = getUserInfo(UserHandle.myUserId()); 870d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani return user != null && user.isGuest(); 871d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani } 872d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani 873d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani /** 8741c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani * Checks if the calling app is running in a demo user. When running in a demo user, 8751c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani * apps can be more helpful to the user, or explain their features in more detail. 8761c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani * 877d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani * @return whether the caller is a demo user. 878d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani */ 879d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani public boolean isDemoUser() { 8801c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani try { 8811c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani return mService.isDemoUser(UserHandle.myUserId()); 8821c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani } catch (RemoteException re) { 8831c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani throw re.rethrowFromSystemServer(); 8841c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani } 8851e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani } 8861e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani 8871e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani /** 8880e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani * Checks if the calling app is running in a managed profile. 8890e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 8900e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani * 8910e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani * @return whether the caller is in a managed profile. 8920e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani * @hide 8930e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani */ 8940e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani @SystemApi 8950e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani public boolean isManagedProfile() { 8968673b2899e775014336efff44ea88dcac2b25bddTony Mak try { 8978673b2899e775014336efff44ea88dcac2b25bddTony Mak return mService.isManagedProfile(UserHandle.myUserId()); 8988673b2899e775014336efff44ea88dcac2b25bddTony Mak } catch (RemoteException re) { 8998673b2899e775014336efff44ea88dcac2b25bddTony Mak throw re.rethrowFromSystemServer(); 9008673b2899e775014336efff44ea88dcac2b25bddTony Mak } 9018673b2899e775014336efff44ea88dcac2b25bddTony Mak } 9028673b2899e775014336efff44ea88dcac2b25bddTony Mak 9038673b2899e775014336efff44ea88dcac2b25bddTony Mak /** 9048673b2899e775014336efff44ea88dcac2b25bddTony Mak * Checks if the specified user is a managed profile. 9058673b2899e775014336efff44ea88dcac2b25bddTony Mak * Requires {@link android.Manifest.permission#MANAGE_USERS} permission, otherwise the caller 9068673b2899e775014336efff44ea88dcac2b25bddTony Mak * must be in the same profile group of specified user. 9078673b2899e775014336efff44ea88dcac2b25bddTony Mak * 9088673b2899e775014336efff44ea88dcac2b25bddTony Mak * @return whether the specified user is a managed profile. 9098673b2899e775014336efff44ea88dcac2b25bddTony Mak * @hide 9108673b2899e775014336efff44ea88dcac2b25bddTony Mak */ 9118673b2899e775014336efff44ea88dcac2b25bddTony Mak @SystemApi 9128673b2899e775014336efff44ea88dcac2b25bddTony Mak public boolean isManagedProfile(@UserIdInt int userId) { 9138673b2899e775014336efff44ea88dcac2b25bddTony Mak try { 9148673b2899e775014336efff44ea88dcac2b25bddTony Mak return mService.isManagedProfile(userId); 9158673b2899e775014336efff44ea88dcac2b25bddTony Mak } catch (RemoteException re) { 9168673b2899e775014336efff44ea88dcac2b25bddTony Mak throw re.rethrowFromSystemServer(); 9178673b2899e775014336efff44ea88dcac2b25bddTony Mak } 9180e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani } 9190e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani 9200e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani /** 921c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova * Checks if the calling app is running as an ephemeral user. 922c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova * 923c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova * @return whether the caller is an ephemeral user. 924c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova * @hide 925c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova */ 926c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova public boolean isEphemeralUser() { 927c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova return isUserEphemeral(UserHandle.myUserId()); 928c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova } 929c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova 930c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova /** 931c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova * Returns whether the specified user is ephemeral. 932c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova * @hide 933c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova */ 9348588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean isUserEphemeral(@UserIdInt int userId) { 935c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova final UserInfo user = getUserInfo(userId); 936c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova return user != null && user.isEphemeral(); 937c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova } 938c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova 939c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova /** 940a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * Return whether the given user is actively running. This means that 941a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * the user is in the "started" state, not "stopped" -- it is currently 942a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * allowed to run code through scheduled alarms, receiving broadcasts, 943a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * etc. A started user may be either the current foreground user or a 944a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * background user; the result here does not distinguish between the two. 945a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * @param user The user to retrieve the running state for. 946a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn */ 947a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn public boolean isUserRunning(UserHandle user) { 9480e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey return isUserRunning(user.getIdentifier()); 9490e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey } 9500e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey 9510e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey /** {@hide} */ 9520e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey public boolean isUserRunning(int userId) { 953ea1b9d7958b4201ca288ea16ed8a8454de6bbca9Amith Yamasani // TODO Switch to using UMS internal isUserRunning 954a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn try { 9550e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey return ActivityManagerNative.getDefault().isUserRunning(userId, 0); 95627b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 957f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 958a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 959a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 960a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn 961a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn /** 962a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * Return whether the given user is actively running <em>or</em> stopping. 963a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * This is like {@link #isUserRunning(UserHandle)}, but will also return 964a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * true if the user had been running but is in the process of being stopped 965a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * (but is not yet fully stopped, and still running some code). 966a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * @param user The user to retrieve the running state for. 967a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn */ 968a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn public boolean isUserRunningOrStopping(UserHandle user) { 969a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn try { 970e17ac1569793c333bb4dce86607a342e7c982ae7Jeff Sharkey // TODO: reconcile stopped vs stopping? 971a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn return ActivityManagerNative.getDefault().isUserRunning( 972e17ac1569793c333bb4dce86607a342e7c982ae7Jeff Sharkey user.getIdentifier(), ActivityManager.FLAG_OR_STOPPED); 97327b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 974f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 975a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 976a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 977a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn 9788a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey /** @removed */ 979b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey @Deprecated 980e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey public boolean isUserRunningAndLocked() { 981e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey return isUserRunningAndLocked(Process.myUserHandle()); 982e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey } 983e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey 9848a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey /** @removed */ 985b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey @Deprecated 9869d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey public boolean isUserRunningAndLocked(UserHandle user) { 9879d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey try { 9889d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey return ActivityManagerNative.getDefault().isUserRunning( 9899d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey user.getIdentifier(), ActivityManager.FLAG_AND_LOCKED); 99027b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 991f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 9929d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey } 9939d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey } 9949d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey 9958a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey /** @removed */ 996b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey @Deprecated 997e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey public boolean isUserRunningAndUnlocked() { 998e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey return isUserRunningAndUnlocked(Process.myUserHandle()); 999e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey } 1000e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey 10018a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey /** @removed */ 1002b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey @Deprecated 10039d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey public boolean isUserRunningAndUnlocked(UserHandle user) { 10040825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey try { 10050825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey return ActivityManagerNative.getDefault().isUserRunning( 10060825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey user.getIdentifier(), ActivityManager.FLAG_AND_UNLOCKED); 100727b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 1008f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 10090825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey } 10100825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey } 10110825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey 10120825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey /** 1013cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * Return whether the calling user is running in an "unlocked" state. 1014cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * <p> 1015cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * On devices with direct boot, a user is unlocked only after they've 1016cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * entered their credentials (such as a lock pattern or PIN). On devices 1017cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * without direct boot, a user is unlocked as soon as it starts. 1018cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * <p> 1019cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * When a user is locked, only device-protected data storage is available. 1020cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * When a user is unlocked, both device-protected and credential-protected 1021cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * private app data storage is available. 10228a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey * 10238a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey * @see Intent#ACTION_USER_UNLOCKED 10248a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey * @see Context#createDeviceProtectedStorageContext() 1025b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey */ 1026b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey public boolean isUserUnlocked() { 1027b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey return isUserUnlocked(Process.myUserHandle()); 1028b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey } 1029b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey 1030b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey /** 1031cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * Return whether the given user is running in an "unlocked" state. 1032cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * <p> 1033cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * On devices with direct boot, a user is unlocked only after they've 1034cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * entered their credentials (such as a lock pattern or PIN). On devices 1035cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * without direct boot, a user is unlocked as soon as it starts. 1036cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * <p> 1037cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * When a user is locked, only device-protected data storage is available. 1038cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * When a user is unlocked, both device-protected and credential-protected 1039cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey * private app data storage is available. 1040b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey * 1041b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey * @param user to retrieve the unlocked state for. 10428a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey * @see Intent#ACTION_USER_UNLOCKED 10438a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey * @see Context#createDeviceProtectedStorageContext() 1044b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey */ 1045b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey public boolean isUserUnlocked(UserHandle user) { 10460999c0d6e9c83873d9595ee764b6388dbc49dcb8Jeff Sharkey return isUserUnlocked(user.getIdentifier()); 10470999c0d6e9c83873d9595ee764b6388dbc49dcb8Jeff Sharkey } 10480999c0d6e9c83873d9595ee764b6388dbc49dcb8Jeff Sharkey 10490999c0d6e9c83873d9595ee764b6388dbc49dcb8Jeff Sharkey /** {@hide} */ 10508588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean isUserUnlocked(@UserIdInt int userId) { 1051ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey try { 1052ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey return ActivityManagerNative.getDefault().isUserRunning(userId, 1053ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey ActivityManager.FLAG_AND_UNLOCKED); 1054ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey } catch (RemoteException re) { 1055ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey throw re.rethrowFromSystemServer(); 1056ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey } 1057ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey } 1058ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey 1059ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey /** {@hide} */ 1060ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey public boolean isUserUnlockingOrUnlocked(UserHandle user) { 1061ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey return isUserUnlockingOrUnlocked(user.getIdentifier()); 1062ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey } 1063ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey 1064ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey /** {@hide} */ 1065ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) { 10666c915ead38db0a2a6393c40d4fbac959399439c5Fyodor Kupolov // TODO Switch to using UMS internal isUserUnlockingOrUnlocked 1067ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey try { 1068ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey return ActivityManagerNative.getDefault().isUserRunning(userId, 1069ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey ActivityManager.FLAG_AND_UNLOCKING_OR_UNLOCKED); 1070ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey } catch (RemoteException re) { 1071ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey throw re.rethrowFromSystemServer(); 1072ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey } 1073b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey } 1074b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey 1075b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey /** 1076258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns the UserInfo object describing a specific user. 10778673b2899e775014336efff44ea88dcac2b25bddTony Mak * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1078258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the user handle of the user whose information is being requested. 1079258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the UserInfo object for a specific user. 1080258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1081b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn */ 10828588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public UserInfo getUserInfo(@UserIdInt int userHandle) { 1083258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 1084258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.getUserInfo(userHandle); 1085258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 1086f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1087258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1088258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1089258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 109071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 1091e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * @hide 1092e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * 1093e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * Returns who set a user restriction on a user. 1094e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1095e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * @param restrictionKey the string key representing the restriction 1096e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 1097e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * @return The source of user restriction. Any combination of {@link #RESTRICTION_NOT_SET}, 1098e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * {@link #RESTRICTION_SOURCE_SYSTEM}, {@link #RESTRICTION_SOURCE_DEVICE_OWNER} 1099e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban * and {@link #RESTRICTION_SOURCE_PROFILE_OWNER} 1100e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban */ 1101e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban @SystemApi 1102e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban @UserRestrictionSource 1103e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban public int getUserRestrictionSource(String restrictionKey, UserHandle userHandle) { 1104e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban try { 1105e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban return mService.getUserRestrictionSource(restrictionKey, userHandle.getIdentifier()); 1106e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban } catch (RemoteException re) { 1107e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban throw re.rethrowFromSystemServer(); 1108e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban } 1109e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban } 1110e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban 1111e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban /** 111271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Returns the user-wide restrictions imposed on this user. 111371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @return a Bundle containing all the restrictions. 111471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 1115e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public Bundle getUserRestrictions() { 1116e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani return getUserRestrictions(Process.myUserHandle()); 1117e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 1118e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 111971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 112071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>. 112171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 112271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @return a Bundle containing all the restrictions. 112371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 1124e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public Bundle getUserRestrictions(UserHandle userHandle) { 1125e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani try { 1126e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani return mService.getUserRestrictions(userHandle.getIdentifier()); 1127e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } catch (RemoteException re) { 1128f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1129e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 1130e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 1131e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 11323bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban /** 11333bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban * @hide 11343bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban * Returns whether the given user has been disallowed from performing certain actions 11353bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban * or setting certain settings through UserManager. This method disregards restrictions 11363bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban * set by device policy. 11373bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban * @param restrictionKey the string key representing the restriction 11383bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 11393bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban */ 11403bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban public boolean hasBaseUserRestriction(String restrictionKey, UserHandle userHandle) { 11413bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban try { 11423bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban return mService.hasBaseUserRestriction(restrictionKey, userHandle.getIdentifier()); 11433bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban } catch (RemoteException re) { 1144f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 11453bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban } 11463bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban } 11473bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban 114871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 1149a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki * This will no longer work. Device owners and profile owners should use 1150a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead. 115171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 1152a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki // System apps should use UserManager.setUserRestriction() instead. 11533d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds @Deprecated 1154e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public void setUserRestrictions(Bundle restrictions) { 1155068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki throw new UnsupportedOperationException("This method is no longer supported"); 1156e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 1157e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 115871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 1159a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki * This will no longer work. Device owners and profile owners should use 1160a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead. 116171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 1162a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki // System apps should use UserManager.setUserRestriction() instead. 11633d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds @Deprecated 1164e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) { 1165068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki throw new UnsupportedOperationException("This method is no longer supported"); 1166e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 1167e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 116871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 116971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Sets the value of a specific restriction. 1170be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani * Requires the MANAGE_USERS permission. 117171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param key the key of the restriction 117271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param value the value for the restriction 11733d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction( 11743d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * android.content.ComponentName, String)} or 11753d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * {@link android.app.admin.DevicePolicyManager#clearUserRestriction( 11763d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * android.content.ComponentName, String)} instead. 117771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 11783d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds @Deprecated 117971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public void setUserRestriction(String key, boolean value) { 1180068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki setUserRestriction(key, value, Process.myUserHandle()); 118171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani } 118271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani 118371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 118471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @hide 118571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Sets the value of a specific restriction on a specific user. 1186be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani * Requires the MANAGE_USERS permission. 118771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param key the key of the restriction 118871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param value the value for the restriction 118971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param userHandle the user whose restriction is to be changed. 11903d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction( 11913d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * android.content.ComponentName, String)} or 11923d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * {@link android.app.admin.DevicePolicyManager#clearUserRestriction( 11933d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * android.content.ComponentName, String)} instead. 119471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 11953d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds @Deprecated 11966794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall public void setUserRestriction(String key, boolean value, UserHandle userHandle) { 1197b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov try { 1198b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov mService.setUserRestriction(key, value, userHandle.getIdentifier()); 1199b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov } catch (RemoteException re) { 1200f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1201b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov } 12026794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall } 12036794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 1204258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 1205a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * Returns whether the current user has been disallowed from performing certain actions 1206a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * or setting certain settings. 12072b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds * 12082b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds * @param restrictionKey The string key representing the restriction. 12092b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds * @return {@code true} if the current user has the given restriction, {@code false} otherwise. 1210a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 1211a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public boolean hasUserRestriction(String restrictionKey) { 1212b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie return hasUserRestriction(restrictionKey, Process.myUserHandle()); 1213b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie } 1214b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie 1215b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie /** 1216b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * @hide 1217b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * Returns whether the given user has been disallowed from performing certain actions 1218b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * or setting certain settings. 1219b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * @param restrictionKey the string key representing the restriction 1220b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 1221b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie */ 1222b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) { 12238cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani try { 12248cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani return mService.hasUserRestriction(restrictionKey, 12258cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani userHandle.getIdentifier()); 12268cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani } catch (RemoteException re) { 1227f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 12288cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani } 1229a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall } 1230a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 1231a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 123233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * Return the serial number for a user. This is a device-unique 1233b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * number assigned to that user; if the user is deleted and then a new 1234b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * user created, the new users will not be given the same serial number. 123533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @param user The user whose serial number is to be retrieved. 1236b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * @return The serial number of the given user; returns -1 if the 1237b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * given UserHandle does not exist. 123833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @see #getUserForSerialNumber(long) 123933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn */ 124033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn public long getSerialNumberForUser(UserHandle user) { 124133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn return getUserSerialNumber(user.getIdentifier()); 124233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn } 124333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn 124433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn /** 124533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * Return the user associated with a serial number previously 124633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * returned by {@link #getSerialNumberForUser(UserHandle)}. 124733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @param serialNumber The serial number of the user that is being 124833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * retrieved. 124933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @return Return the user associated with the serial number, or null 125033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * if there is not one. 125133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @see #getSerialNumberForUser(UserHandle) 125233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn */ 125333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn public UserHandle getUserForSerialNumber(long serialNumber) { 1254ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov int ident = getUserHandle((int) serialNumber); 125533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn return ident >= 0 ? new UserHandle(ident) : null; 125633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn } 125733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn 125833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn /** 1259cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen * Creates a user with the specified name and options. For non-admin users, default user 1260cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen * restrictions are going to be applied. 12611952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1262258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 1263258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param name the user's name 1264258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param flags flags that identify the type of user and other properties. 1265258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @see UserInfo 1266258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 1267258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the UserInfo object for the created user, or null if the user could not be created. 1268258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1269258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 1270258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public UserInfo createUser(String name, int flags) { 1271cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen UserInfo user = null; 1272258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 1273cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen user = mService.createUser(name, flags); 1274e9c440638e27a123a82feb5e4677ce1242785288phweiss // TODO: Keep this in sync with 1275e9c440638e27a123a82feb5e4677ce1242785288phweiss // UserManagerService.LocalService.createUserEvenWhenDisallowed 1276cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen if (user != null && !user.isAdmin()) { 1277068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki mService.setUserRestriction(DISALLOW_SMS, true, user.id); 1278068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki mService.setUserRestriction(DISALLOW_OUTGOING_CALLS, true, user.id); 1279cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen } 1280258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 1281f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1282258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1283cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen return user; 1284258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1285258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 1286258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 12871e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * Creates a guest user and configures it. 12881e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * @param context an application context 12891e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * @param name the name to set for the user 12901e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * @hide 12911e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani */ 12921e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani public UserInfo createGuest(Context context, String name) { 1293068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki UserInfo guest = null; 1294068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki try { 1295068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki guest = mService.createUser(name, UserInfo.FLAG_GUEST); 1296068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki if (guest != null) { 1297068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki Settings.Secure.putStringForUser(context.getContentResolver(), 1298068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id); 1299bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani } 1300068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki } catch (RemoteException re) { 1301f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 13021e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani } 13031e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani return guest; 13041e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani } 13051e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani 1306aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani /** 13072a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * Creates a user with the specified name and options as a profile of another user. 1308a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1309a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * 1310a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @param name the user's name 1311a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @param flags flags that identify the type of user and other properties. 1312a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @see UserInfo 13132a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * @param userHandle new user will be a profile of this use. 1314a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * 1315a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @return the UserInfo object for the created user, or null if the user could not be created. 1316a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @hide 1317a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy */ 13188588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle) { 1319a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy try { 13202a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy return mService.createProfileForUser(name, flags, userHandle); 1321a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } catch (RemoteException re) { 1322f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1323a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } 1324a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } 1325a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy 1326a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy /** 132702cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov * Creates a restricted profile with the specified name. This method also sets necessary 132802cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov * restrictions and adds shared accounts. 132906a484adb93c6c969321147b07112684383305f6Fyodor Kupolov * 133006a484adb93c6c969321147b07112684383305f6Fyodor Kupolov * @param name profile's name 133106a484adb93c6c969321147b07112684383305f6Fyodor Kupolov * @return UserInfo object for the created user, or null if the user could not be created. 133206a484adb93c6c969321147b07112684383305f6Fyodor Kupolov * @hide 133306a484adb93c6c969321147b07112684383305f6Fyodor Kupolov */ 133406a484adb93c6c969321147b07112684383305f6Fyodor Kupolov public UserInfo createRestrictedProfile(String name) { 133506a484adb93c6c969321147b07112684383305f6Fyodor Kupolov try { 133602cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov UserHandle parentUserHandle = Process.myUserHandle(); 133702cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov UserInfo user = mService.createRestrictedProfile(name, 133802cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov parentUserHandle.getIdentifier()); 133902cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov if (user != null) { 134002cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov AccountManager.get(mContext).addSharedAccountsFromParentUser(parentUserHandle, 134102cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov UserHandle.of(user.id)); 134206a484adb93c6c969321147b07112684383305f6Fyodor Kupolov } 134302cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov return user; 134427b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 1345f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 134606a484adb93c6c969321147b07112684383305f6Fyodor Kupolov } 134706a484adb93c6c969321147b07112684383305f6Fyodor Kupolov } 134806a484adb93c6c969321147b07112684383305f6Fyodor Kupolov 134906a484adb93c6c969321147b07112684383305f6Fyodor Kupolov /** 13500696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * Returns an intent to create a user for the provided name and account name. The name 13510696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * and account name will be used when the setup process for the new user is started. 13520696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * <p> 135312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * The intent should be launched using startActivityForResult and the return result will 135437ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * indicate if the user consented to adding a new user and if the operation succeeded. Any 135537ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * errors in creating the user will be returned in the result code. If the user cancels the 135637ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * request, the return result will be {@link Activity#RESULT_CANCELED}. On success, the 135737ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * result code will be {@link Activity#RESULT_OK}. 13580696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * <p> 13590696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * Use {@link #supportsMultipleUsers()} to first check if the device supports this operation 13600696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * at all. 13610696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * <p> 136212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * The new user is created but not initialized. After switching into the user for the first 136312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * time, the preferred user name and account information are used by the setup process for that 136412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * user. 136512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * 136612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param userName Optional name to assign to the user. 13670696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * @param accountName Optional account name that will be used by the setup wizard to initialize 136812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * the user. 136912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param accountType Optional account type for the account to be created. This is required 137012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * if the account name is specified. 137112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param accountOptions Optional bundle of data to be passed in during account creation in the 137212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * new user via {@link AccountManager#addAccount(String, String, String[], 137312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Bundle, android.app.Activity, android.accounts.AccountManagerCallback, 137412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Handler)}. 13750696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * @return An Intent that can be launched from an Activity. 137637ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * @see #USER_CREATION_FAILED_NOT_PERMITTED 137737ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * @see #USER_CREATION_FAILED_NO_MORE_USERS 13780696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * @see #supportsMultipleUsers 137912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 138012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public static Intent createUserCreationIntent(@Nullable String userName, 138112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani @Nullable String accountName, 138212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani @Nullable String accountType, @Nullable PersistableBundle accountOptions) { 138312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani Intent intent = new Intent(ACTION_CREATE_USER); 138412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani if (userName != null) { 138512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani intent.putExtra(EXTRA_USER_NAME, userName); 138612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 138712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani if (accountName != null && accountType == null) { 138812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani throw new IllegalArgumentException("accountType must be specified if accountName is " 138912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani + "specified"); 139012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 139112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani if (accountName != null) { 139212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani intent.putExtra(EXTRA_USER_ACCOUNT_NAME, accountName); 139312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 139412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani if (accountType != null) { 139512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani intent.putExtra(EXTRA_USER_ACCOUNT_TYPE, accountType); 139612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 139712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani if (accountOptions != null) { 139812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani intent.putExtra(EXTRA_USER_ACCOUNT_OPTIONS, accountOptions); 139912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 140012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani return intent; 140112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 140212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 140312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 140412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 140512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * 140612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Returns the preferred account name for user creation. Requires MANAGE_USERS permission. 140712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 140812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani @SystemApi 140912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public String getSeedAccountName() { 141012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani try { 141112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani return mService.getSeedAccountName(); 141212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } catch (RemoteException re) { 1413f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 141412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 141512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 141612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 141712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 141812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 141912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * 142012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Returns the preferred account type for user creation. Requires MANAGE_USERS permission. 142112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 142212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani @SystemApi 142312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public String getSeedAccountType() { 142412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani try { 142512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani return mService.getSeedAccountType(); 142612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } catch (RemoteException re) { 1427f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 142812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 142912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 143012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 143112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 143212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 143312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * 143412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Returns the preferred account's options bundle for user creation. Requires MANAGE_USERS 143512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * permission. 143612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @return Any options set by the requestor that created the user. 143712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 143812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani @SystemApi 143912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public PersistableBundle getSeedAccountOptions() { 144012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani try { 144112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani return mService.getSeedAccountOptions(); 144212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } catch (RemoteException re) { 1443f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 144412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 144512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 144612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 144712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 144812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 144912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * 145012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Called by a system activity to set the seed account information of a user created 145112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * through the user creation intent. 145212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param userId 145312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param accountName 145412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param accountType 145512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param accountOptions 145612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @see #createUserCreationIntent(String, String, String, PersistableBundle) 145712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 145812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public void setSeedAccountData(int userId, String accountName, String accountType, 145912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani PersistableBundle accountOptions) { 146012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani try { 146112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani mService.setSeedAccountData(userId, accountName, accountType, accountOptions, 146212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /* persist= */ true); 146312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } catch (RemoteException re) { 1464f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 146512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 146612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 146712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 146812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 146912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 147012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Clears the seed information used to create this user. Requires MANAGE_USERS permission. 147112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 147212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani @SystemApi 147312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public void clearSeedAccountData() { 147412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani try { 147512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani mService.clearSeedAccountData(); 147612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } catch (RemoteException re) { 1477f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 147812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 147912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 148012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 148112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 14821df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani * @hide 14831df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani * Marks the guest user for deletion to allow a new guest to be created before deleting 14841df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani * the current user who is a guest. 14851df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani * @param userHandle 14861df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani * @return 14871df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani */ 14888588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean markGuestForDeletion(@UserIdInt int userHandle) { 14891df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani try { 14901df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani return mService.markGuestForDeletion(userHandle); 14911df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani } catch (RemoteException re) { 1492f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 14931df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani } 14941df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani } 14951df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani 14961df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani /** 1497df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina * Sets the user as enabled, if such an user exists. 14981ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova * 14991ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 15001ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova * 15011ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova * <p>Note that the default is true, it's only that managed profiles might not be enabled. 15021ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova * Also ephemeral users can be disabled to indicate that their removal is in progress and they 15031ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova * shouldn't be re-entered. Therefore ephemeral users should not be re-enabled once disabled. 1504df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina * 1505df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina * @param userHandle the id of the profile to enable 1506df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina * @hide 1507df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina */ 15088588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public void setUserEnabled(@UserIdInt int userHandle) { 1509df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina try { 1510df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina mService.setUserEnabled(userHandle); 151127b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 1512f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1513df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina } 1514df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina } 1515df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina 1516df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina /** 1517b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * Return the number of users currently created on the device. 1518b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn */ 1519b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn public int getUserCount() { 1520b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn List<UserInfo> users = getUsers(); 1521b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn return users != null ? users.size() : 1; 1522b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn } 1523b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn 1524b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn /** 1525d04aaa323c3a788d26f18fc66e0a59b47e525b38Amith Yamasani * Returns information for all users on this device, including ones marked for deletion. 1526d04aaa323c3a788d26f18fc66e0a59b47e525b38Amith Yamasani * To retrieve only users that are alive, use {@link #getUsers(boolean)}. 1527d04aaa323c3a788d26f18fc66e0a59b47e525b38Amith Yamasani * <p> 15281952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1529940e8577a1569140521fb605336997863529f7adFyodor Kupolov * @return the list of users that exist on the device. 1530258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1531258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 1532258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public List<UserInfo> getUsers() { 1533258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 1534920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani return mService.getUsers(false); 1535920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani } catch (RemoteException re) { 1536f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1537920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani } 1538920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani } 1539920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani 1540920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani /** 1541940e8577a1569140521fb605336997863529f7adFyodor Kupolov * Returns serial numbers of all users on this device. 1542940e8577a1569140521fb605336997863529f7adFyodor Kupolov * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1543940e8577a1569140521fb605336997863529f7adFyodor Kupolov * 1544940e8577a1569140521fb605336997863529f7adFyodor Kupolov * @param excludeDying specify if the list should exclude users being removed. 1545940e8577a1569140521fb605336997863529f7adFyodor Kupolov * @return the list of serial numbers of users that exist on the device. 1546940e8577a1569140521fb605336997863529f7adFyodor Kupolov * @hide 1547940e8577a1569140521fb605336997863529f7adFyodor Kupolov */ 1548940e8577a1569140521fb605336997863529f7adFyodor Kupolov @SystemApi 1549940e8577a1569140521fb605336997863529f7adFyodor Kupolov public long[] getSerialNumbersOfUsers(boolean excludeDying) { 1550940e8577a1569140521fb605336997863529f7adFyodor Kupolov try { 1551940e8577a1569140521fb605336997863529f7adFyodor Kupolov List<UserInfo> users = mService.getUsers(excludeDying); 1552940e8577a1569140521fb605336997863529f7adFyodor Kupolov long[] result = new long[users.size()]; 1553940e8577a1569140521fb605336997863529f7adFyodor Kupolov for (int i = 0; i < result.length; i++) { 1554940e8577a1569140521fb605336997863529f7adFyodor Kupolov result[i] = users.get(i).serialNumber; 1555940e8577a1569140521fb605336997863529f7adFyodor Kupolov } 1556940e8577a1569140521fb605336997863529f7adFyodor Kupolov return result; 1557940e8577a1569140521fb605336997863529f7adFyodor Kupolov } catch (RemoteException re) { 1558f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1559940e8577a1569140521fb605336997863529f7adFyodor Kupolov } 1560940e8577a1569140521fb605336997863529f7adFyodor Kupolov } 1561940e8577a1569140521fb605336997863529f7adFyodor Kupolov 1562940e8577a1569140521fb605336997863529f7adFyodor Kupolov /** 1563b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen * @return the user's account name, null if not found. 1564b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen * @hide 1565b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen */ 1566b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen @RequiresPermission( allOf = { 1567b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen Manifest.permission.INTERACT_ACROSS_USERS_FULL, 1568b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen Manifest.permission.MANAGE_USERS 1569b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen }) 15708588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public @Nullable String getUserAccount(@UserIdInt int userHandle) { 1571b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen try { 1572b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen return mService.getUserAccount(userHandle); 1573b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen } catch (RemoteException re) { 1574f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1575b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen } 1576b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen } 1577b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen 1578b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen /** 1579b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen * Set account name for the given user. 1580b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen * @hide 1581b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen */ 1582b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen @RequiresPermission( allOf = { 1583b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen Manifest.permission.INTERACT_ACROSS_USERS_FULL, 1584b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen Manifest.permission.MANAGE_USERS 1585b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen }) 15868588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public void setUserAccount(@UserIdInt int userHandle, @Nullable String accountName) { 1587b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen try { 1588b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen mService.setUserAccount(userHandle, accountName); 1589b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen } catch (RemoteException re) { 1590f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1591b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen } 1592b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen } 1593b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen 1594b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen /** 159570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * Returns information for Primary user. 159670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 159770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * 159870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * @return the Primary user, null if not found. 159970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * @hide 160070f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen */ 16017cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen public @Nullable UserInfo getPrimaryUser() { 160270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen try { 160370f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen return mService.getPrimaryUser(); 160470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen } catch (RemoteException re) { 1605f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 160670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen } 160770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen } 160870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen 160970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen /** 161095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS 161195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani * permission. 161295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani * 161395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani * @return true if more users can be added, false if limit has been reached. 161495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani * @hide 161595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani */ 161695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani public boolean canAddMoreUsers() { 161795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani final List<UserInfo> users = getUsers(true); 161895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani final int totalUserCount = users.size(); 161995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani int aliveUserCount = 0; 162095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani for (int i = 0; i < totalUserCount; i++) { 162195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani UserInfo user = users.get(i); 162295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani if (!user.isGuest()) { 162395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani aliveUserCount++; 162495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani } 162595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani } 162695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani return aliveUserCount < getMaxSupportedUsers(); 162795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani } 162895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani 162995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani /** 163072434b7088591828082dd952496d523ef3622de2Nicolas Prevot * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS 163172434b7088591828082dd952496d523ef3622de2Nicolas Prevot * permission. 163207387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot * if allowedToRemoveOne is true and if the user already has a managed profile, then return if 163307387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot * we could add a new managed profile to this user after removing the existing one. 163472434b7088591828082dd952496d523ef3622de2Nicolas Prevot * 163572434b7088591828082dd952496d523ef3622de2Nicolas Prevot * @return true if more managed profiles can be added, false if limit has been reached. 163672434b7088591828082dd952496d523ef3622de2Nicolas Prevot * @hide 163772434b7088591828082dd952496d523ef3622de2Nicolas Prevot */ 16388588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean canAddMoreManagedProfiles(@UserIdInt int userId, boolean allowedToRemoveOne) { 163972434b7088591828082dd952496d523ef3622de2Nicolas Prevot try { 164007387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot return mService.canAddMoreManagedProfiles(userId, allowedToRemoveOne); 164172434b7088591828082dd952496d523ef3622de2Nicolas Prevot } catch (RemoteException re) { 1642f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 164372434b7088591828082dd952496d523ef3622de2Nicolas Prevot } 164472434b7088591828082dd952496d523ef3622de2Nicolas Prevot } 164572434b7088591828082dd952496d523ef3622de2Nicolas Prevot 164672434b7088591828082dd952496d523ef3622de2Nicolas Prevot /** 16472a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * Returns list of the profiles of userHandle including 16482a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * userHandle itself. 16494f7e2e334e4ca5f1a67baf4bdd40cd080b954161Amith Yamasani * Note that this returns both enabled and not enabled profiles. See 16507f75da2405cd910854448bb3801f776e036f926aRuben Brunk * {@link #getEnabledProfiles(int)} if you need only the enabled ones. 16514f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * 16522a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 16532a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * @param userHandle profiles of this user will be returned. 16542a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * @return the list of profiles. 16552a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * @hide 16562a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy */ 16578588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public List<UserInfo> getProfiles(@UserIdInt int userHandle) { 1658a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy try { 1659385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina return mService.getProfiles(userHandle, false /* enabledOnly */); 1660a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } catch (RemoteException re) { 1661f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1662a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } 1663a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } 1664a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy 1665a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy /** 1666fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1667fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen * @param userId one of the two user ids to check. 1668fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen * @param otherUserId one of the two user ids to check. 1669fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen * @return true if the two user ids are in the same profile group. 1670fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen * @hide 1671fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen */ 16728588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean isSameProfileGroup(@UserIdInt int userId, int otherUserId) { 1673fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen try { 1674fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen return mService.isSameProfileGroup(userId, otherUserId); 1675fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen } catch (RemoteException re) { 1676f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1677fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen } 1678fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen } 1679fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen 1680fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen /** 16817f75da2405cd910854448bb3801f776e036f926aRuben Brunk * Returns list of the profiles of userHandle including 16827f75da2405cd910854448bb3801f776e036f926aRuben Brunk * userHandle itself. 16837f75da2405cd910854448bb3801f776e036f926aRuben Brunk * Note that this returns only enabled. 16847f75da2405cd910854448bb3801f776e036f926aRuben Brunk * 16857f75da2405cd910854448bb3801f776e036f926aRuben Brunk * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 16867f75da2405cd910854448bb3801f776e036f926aRuben Brunk * @param userHandle profiles of this user will be returned. 16877f75da2405cd910854448bb3801f776e036f926aRuben Brunk * @return the list of profiles. 16887f75da2405cd910854448bb3801f776e036f926aRuben Brunk * @hide 16897f75da2405cd910854448bb3801f776e036f926aRuben Brunk */ 16908588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public List<UserInfo> getEnabledProfiles(@UserIdInt int userHandle) { 16917f75da2405cd910854448bb3801f776e036f926aRuben Brunk try { 16927f75da2405cd910854448bb3801f776e036f926aRuben Brunk return mService.getProfiles(userHandle, true /* enabledOnly */); 16937f75da2405cd910854448bb3801f776e036f926aRuben Brunk } catch (RemoteException re) { 1694f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 16957f75da2405cd910854448bb3801f776e036f926aRuben Brunk } 16967f75da2405cd910854448bb3801f776e036f926aRuben Brunk } 16977f75da2405cd910854448bb3801f776e036f926aRuben Brunk 16987f75da2405cd910854448bb3801f776e036f926aRuben Brunk /** 1699be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * Returns a list of UserHandles for profiles associated with the user that the calling process 1700be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * is running on, including the user itself. 17014f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * 17024f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * @return A non-empty list of UserHandles associated with the calling user. 17034f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani */ 17044f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani public List<UserHandle> getUserProfiles() { 17057f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov int[] userIds = getProfileIds(UserHandle.myUserId(), true /* enabledOnly */); 17067f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov List<UserHandle> result = new ArrayList<>(userIds.length); 17077f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov for (int userId : userIds) { 17087f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov result.add(UserHandle.of(userId)); 17097f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov } 17107f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov return result; 17117f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov } 17127f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov 17137f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov /** 17147f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * Returns a list of ids for profiles associated with the specified user including the user 17157f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * itself. 17167f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * 17177f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * @param userId id of the user to return profiles for 17187f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * @param enabledOnly whether return only {@link UserInfo#isEnabled() enabled} profiles 17197f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * @return A non-empty list of ids of profiles associated with the specified user. 17207f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * 17217f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * @hide 17227f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov */ 17237f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov public int[] getProfileIds(@UserIdInt int userId, boolean enabledOnly) { 1724385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina try { 17257f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov return mService.getProfileIds(userId, enabledOnly); 1726385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina } catch (RemoteException re) { 1727f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1728385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina } 17297f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov } 17307f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov 17317f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov /** 17327f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * @see #getProfileIds(int, boolean) 17337f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * @hide 17347f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov */ 17357f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov public int[] getProfileIdsWithDisabled(@UserIdInt int userId) { 17367f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov return getProfileIds(userId, false /* enabledOnly */); 17377f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov } 17387f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov 17397f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov /** 17407f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * @see #getProfileIds(int, boolean) 17417f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov * @hide 17427f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov */ 17437f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov public int[] getEnabledProfileIds(@UserIdInt int userId) { 17447f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov return getProfileIds(userId, true /* enabledOnly */); 17454f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani } 17464f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani 17477dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani /** 1748c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales * Returns the device credential owner id of the profile from 1749c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales * which this method is called, or userHandle if called from a user that 1750c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales * is not a profile. 1751c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales * 1752c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales * @hide 1753c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales */ 17548588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public int getCredentialOwnerProfile(@UserIdInt int userHandle) { 1755c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales try { 1756c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales return mService.getCredentialOwnerProfile(userHandle); 1757c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales } catch (RemoteException re) { 1758f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1759c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales } 1760c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales } 1761c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales 1762c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales /** 1763be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * Returns the parent of the profile which this method is called from 1764be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * or null if called from a user that is not a profile. 1765be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * 1766be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * @hide 1767be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel */ 17688588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public UserInfo getProfileParent(@UserIdInt int userHandle) { 1769be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel try { 1770be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel return mService.getProfileParent(userHandle); 1771be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel } catch (RemoteException re) { 1772f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1773be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel } 1774be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel } 1775be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel 1776be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel /** 17770a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * Set quiet mode of a managed profile. 17780a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * 17790a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * @param userHandle The user handle of the profile. 17800a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * @param enableQuietMode Whether quiet mode should be enabled or disabled. 17810a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * @hide 17820a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu */ 17838588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public void setQuietModeEnabled(@UserIdInt int userHandle, boolean enableQuietMode) { 17840a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu try { 17850a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu mService.setQuietModeEnabled(userHandle, enableQuietMode); 178627b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 1787f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 17880a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu } 17890a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu } 17900a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu 17910a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu /** 17920a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * Returns whether the given profile is in quiet mode or not. 17937881cf8f818317cc6efe4d6a4c42da94d6bab223Ricky Wai * Notes: Quiet mode is only supported for managed profiles. 17940a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * 17950a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * @param userHandle The user handle of the profile to be queried. 17960a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * @return true if the profile is in quiet mode, false otherwise. 17970a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu */ 17980a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu public boolean isQuietModeEnabled(UserHandle userHandle) { 17990a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu try { 18000a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu return mService.isQuietModeEnabled(userHandle.getIdentifier()); 180127b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 1802f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 18030a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu } 18040a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu } 18050a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu 18060a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu /** 1807f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz * Tries disabling quiet mode for a given user. If the user is still locked, we unlock the user 1808f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz * first by showing the confirm credentials screen and disable quiet mode upon successful 1809f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz * unlocking. If the user is already unlocked, we call through to {@link #setQuietModeEnabled} 1810f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz * directly. 1811f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz * 1812f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz * @return true if the quiet mode was disabled immediately 1813f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz * @hide 1814f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz */ 1815f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz public boolean trySetQuietModeDisabled(@UserIdInt int userHandle, IntentSender target) { 1816f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz try { 1817f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz return mService.trySetQuietModeDisabled(userHandle, target); 1818f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz } catch (RemoteException re) { 1819f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz throw re.rethrowFromSystemServer(); 1820f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz } 1821f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz } 1822f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz 1823f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz /** 18247dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani * If the target user is a managed profile of the calling user or the caller 18257dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani * is itself a managed profile, then this returns a badged copy of the given 1826c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * icon to be able to distinguish it from the original icon. For badging an 1827c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * arbitrary drawable use {@link #getBadgedDrawableForUser( 1828c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}. 1829c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * <p> 1830c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * If the original drawable is a BitmapDrawable and the backing bitmap is 183166ae66a7f74ee835807a141a216afbb254664510Vadim Tryshev * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging 1832c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * is performed in place and the original drawable is returned. 1833c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * </p> 1834c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * 1835c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param icon The icon to badge. 1836c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param user The target user. 1837c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @return A drawable that combines the original icon and a badge as 1838c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * determined by the system. 1839c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav * @removed 1840c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav */ 1841c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) { 1842c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav return mContext.getPackageManager().getUserBadgedIcon(icon, user); 1843c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav } 1844c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav 1845c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav /** 1846c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * If the target user is a managed profile of the calling user or the caller 1847c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * is itself a managed profile, then this returns a badged copy of the given 1848c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * drawable allowing the user to distinguish it from the original drawable. 1849c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * The caller can specify the location in the bounds of the drawable to be 1850c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * badged where the badge should be applied as well as the density of the 1851c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * badge to be used. 1852c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * <p> 1853c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * If the original drawable is a BitmapDrawable and the backing bitmap is 185466ae66a7f74ee835807a141a216afbb254664510Vadim Tryshev * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging 1855c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * is performed in place and the original drawable is returned. 1856c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * </p> 1857c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * 1858c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param badgedDrawable The drawable to badge. 1859c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param user The target user. 1860c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param badgeLocation Where in the bounds of the badged drawable to place 186166ae66a7f74ee835807a141a216afbb254664510Vadim Tryshev * the badge. If it's {@code null}, the badge is applied on top of the entire 1862c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * drawable being badged. 1863c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param badgeDensity The optional desired density for the badge as per 186466ae66a7f74ee835807a141a216afbb254664510Vadim Tryshev * {@link android.util.DisplayMetrics#densityDpi}. If it's not positive, 1865c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * the density of the display is used. 1866c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @return A drawable that combines the original drawable and a badge as 1867c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * determined by the system. 1868c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav * @removed 1869c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav */ 1870c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user, 1871c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav Rect badgeLocation, int badgeDensity) { 1872c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user, 1873c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav badgeLocation, badgeDensity); 18744f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani } 18754f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani 1876701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy /** 1877701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy * If the target user is a managed profile of the calling user or the caller 1878f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * is itself a managed profile, then this returns a copy of the label with 1879f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * badging for accessibility services like talkback. E.g. passing in "Email" 1880f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * and it might return "Work Email" for Email in the work profile. 1881f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * 1882f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * @param label The label to change. 1883f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * @param user The target user. 1884f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * @return A label that combines the original label and a badge as 1885f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * determined by the system. 1886c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav * @removed 1887f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy */ 1888237aecd18d0edf56c038761f570758c310c9e6dfKenny Guy public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) { 1889c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav return mContext.getPackageManager().getUserBadgedLabel(label, user); 18904f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani } 18914f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani 18924f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani /** 18934f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * Returns information for all users on this device. Requires 18944f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * {@link android.Manifest.permission#MANAGE_USERS} permission. 1895394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier * 18964f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * @param excludeDying specify if the list should exclude users being 18974f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * removed. 1898920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani * @return the list of users that were created. 1899920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani * @hide 1900920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani */ 1901920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani public List<UserInfo> getUsers(boolean excludeDying) { 1902920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani try { 1903920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani return mService.getUsers(excludeDying); 1904258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 1905f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1906258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1907258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1908258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 1909258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 1910258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Removes a user and all associated data. 19111952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1912258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the integer handle of the user, where 0 is the primary user. 1913258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1914258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 19158588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean removeUser(@UserIdInt int userHandle) { 1916258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 1917258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.removeUser(userHandle); 1918258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 1919f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1920258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1921258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1922258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 1923258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 1924258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Updates the user's name. 19251952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1926258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 1927258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the user's integer handle 1928258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param name the new name for the user 1929258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1930258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 19318588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public void setUserName(@UserIdInt int userHandle, String name) { 1932258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 1933258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mService.setUserName(userHandle, name); 1934258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 1935f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1936258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1937258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1938258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 1939258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 1940e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * Sets the user's photo. 1941258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the user for whom to change the photo. 1942e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * @param icon the bitmap to set as the photo. 1943258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1944258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 19458588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public void setUserIcon(@UserIdInt int userHandle, Bitmap icon) { 1946258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 1947e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani mService.setUserIcon(userHandle, icon); 1948258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 1949f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 1950258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1951258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1952258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 1953258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 19543b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani * Returns a file descriptor for the user's photo. PNG data can be read from this file. 19553b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani * @param userHandle the user whose photo we want to read. 1956e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * @return a {@link Bitmap} of the user's photo, or null if there's no photo. 195764d4dca63f65e4c7d4a829c85ff6670bdd34e2ebAlexandra Gherghina * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default. 19583b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani * @hide 19593b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani */ 19608588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public Bitmap getUserIcon(@UserIdInt int userHandle) { 19613b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani try { 19621bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos ParcelFileDescriptor fd = mService.getUserIcon(userHandle); 19631bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos if (fd != null) { 19641bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos try { 19651bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor()); 19661bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos } finally { 19671bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos try { 19681bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos fd.close(); 19691bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos } catch (IOException e) { 19701bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos } 19711bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos } 19721bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos } 19733b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani } catch (RemoteException re) { 1974f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 19753b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani } 19761bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos return null; 19773b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani } 19783b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani 19793b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani /** 1980258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns the maximum number of users that can be created on this device. A return value 1981258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * of 1 means that it is a single user device. 1982258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1983a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @return a value greater than or equal to 1 1984258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 198527bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey public static int getMaxSupportedUsers() { 1986ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani // Don't allow multiple users on certain builds 1987ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani if (android.os.Build.ID.startsWith("JVP")) return 1; 1988409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn // Svelte devices don't get multi-user. 1989409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn if (ActivityManager.isLowRamDeviceStatic()) return 1; 199027bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey return SystemProperties.getInt("fw.max_users", 199127bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers)); 1992258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 19932a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani 19942a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani /** 1995cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov * Returns true if the user switcher should be shown, this will be if device supports multi-user 1996cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov * and there are at least 2 users available that are not managed profiles. 19971a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy * @hide 19981a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy * @return true if user switcher should be shown. 19991a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy */ 20001a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy public boolean isUserSwitcherEnabled() { 2001cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov if (!supportsMultipleUsers()) { 2002cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov return false; 2003cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov } 2004eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani // If Demo Mode is on, don't show user switcher 2005eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani if (isDeviceInDemoMode(mContext)) { 2006eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani return false; 2007eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani } 20081a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy List<UserInfo> users = getUsers(true); 20091a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy if (users == null) { 20101a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy return false; 20111a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy } 20121a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy int switchableUserCount = 0; 20131a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy for (UserInfo user : users) { 20147cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen if (user.supportsSwitchToByUser()) { 20151a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy ++switchableUserCount; 20161a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy } 20171a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy } 2018cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class) 2019cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov .getGuestUserDisabled(null); 2020a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani return switchableUserCount > 1 || guestEnabled; 20211a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy } 20221a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy 20231a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy /** 2024eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani * @hide 2025eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani */ 2026eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani public static boolean isDeviceInDemoMode(Context context) { 2027eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani return Settings.Global.getInt(context.getContentResolver(), 2028eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani Settings.Global.DEVICE_DEMO_MODE, 0) > 0; 2029eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani } 2030eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani 2031eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani /** 20322a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * Returns a serial number on this device for a given userHandle. User handles can be recycled 20332a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * when deleting and creating users, but serial numbers are not reused until the device is wiped. 20342a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @param userHandle 20352a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @return a serial number associated with that user, or -1 if the userHandle is not valid. 20362a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @hide 20372a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani */ 20388588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public int getUserSerialNumber(@UserIdInt int userHandle) { 20392a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani try { 20402a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani return mService.getUserSerialNumber(userHandle); 20412a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } catch (RemoteException re) { 2042f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 20432a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 20442a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 20452a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani 20462a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani /** 20472a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * Returns a userHandle on this device for a given user serial number. User handles can be 20482a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * recycled when deleting and creating users, but serial numbers are not reused until the device 20492a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * is wiped. 20502a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @param userSerialNumber 20512a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @return the userHandle associated with that user serial number, or -1 if the serial number 20522a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * is not valid. 20532a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @hide 20542a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani */ 20558588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public @UserIdInt int getUserHandle(int userSerialNumber) { 20562a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani try { 20572a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani return mService.getUserHandle(userSerialNumber); 20582a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } catch (RemoteException re) { 2059f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 20602a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 20612a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 20626794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 20637e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani /** 2064953fe483298bff46558a4e0b2d891924c0c9c813Esteban Talavera * Returns a {@link Bundle} containing any saved application restrictions for this user, for the 20657e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani * given package name. Only an application with this package name can call this method. 20665b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * 20675b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * <p>The returned {@link Bundle} consists of key-value pairs, as defined by the application, 20685b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * where the types of values may be: 20695b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * <ul> 20705b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * <li>{@code boolean} 20715b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * <li>{@code int} 20725b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * <li>{@code String} or {@code String[]} 20735b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} 20745b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * </ul> 20755b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * 20764e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolov * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread 20774e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolov * 20787e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani * @param packageName the package name of the calling application 2079953fe483298bff46558a4e0b2d891924c0c9c813Esteban Talavera * @return a {@link Bundle} with the restrictions for that package, or an empty {@link Bundle} 2080953fe483298bff46558a4e0b2d891924c0c9c813Esteban Talavera * if there are no saved restrictions. 20815b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * 20825b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * @see #KEY_RESTRICTIONS_PENDING 20837e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani */ 20844e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolov @WorkerThread 20857e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani public Bundle getApplicationRestrictions(String packageName) { 20867e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani try { 20877e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani return mService.getApplicationRestrictions(packageName); 20887e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani } catch (RemoteException re) { 2089f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 20907e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani } 20917e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani } 2092df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 2093df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani /** 2094df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * @hide 2095df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani */ 20964e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolov @WorkerThread 20977e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani public Bundle getApplicationRestrictions(String packageName, UserHandle user) { 2098df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani try { 20997e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier()); 2100df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } catch (RemoteException re) { 2101f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 2102df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 2103df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 2104df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 2105df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani /** 2106df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * @hide 2107df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani */ 21084e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolov @WorkerThread 21097e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani public void setApplicationRestrictions(String packageName, Bundle restrictions, 2110df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani UserHandle user) { 2111df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani try { 21127e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier()); 2113df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } catch (RemoteException re) { 2114f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 2115df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 2116df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 2117655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani 2118655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** 2119d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * Sets a new challenge PIN for restrictions. This is only for use by pre-installed 2120d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * apps and requires the MANAGE_USERS permission. 2121d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * @param newPin the PIN to use for challenge dialogs. 2122d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * @return Returns true if the challenge PIN was set successfully. 2123ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov * @deprecated The restrictions PIN functionality is no longer provided by the system. 2124ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov * This method is preserved for backwards compatibility reasons and always returns false. 2125655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani */ 2126514c5ef8d5774d8820ed1bf90fe53af1606cf106Aurimas Liutikas @Deprecated 2127d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani public boolean setRestrictionsChallenge(String newPin) { 2128655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani return false; 2129655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani } 21301a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani 2131e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani /** 2132e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani * @hide 2133e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani * Set restrictions that should apply to any future guest user that's created. 2134e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani */ 2135e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani public void setDefaultGuestRestrictions(Bundle restrictions) { 2136e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani try { 2137e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani mService.setDefaultGuestRestrictions(restrictions); 2138e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } catch (RemoteException re) { 2139f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 2140e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } 2141e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } 2142e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani 2143e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani /** 2144e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani * @hide 2145e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani * Gets the default guest restrictions. 2146e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani */ 2147e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani public Bundle getDefaultGuestRestrictions() { 2148e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani try { 2149e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani return mService.getDefaultGuestRestrictions(); 2150e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } catch (RemoteException re) { 2151f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 2152e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } 2153e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } 2154ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov 2155ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov /** 2156ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov * Returns creation time of the user or of a managed profile associated with the calling user. 2157ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov * @param userHandle user handle of the user or a managed profile associated with the 2158ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov * calling user. 2159ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov * @return creation time in milliseconds since Epoch time. 2160ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov */ 2161385de624aa990266ffbaf70711ac8a330569429eFyodor Kupolov public long getUserCreationTime(UserHandle userHandle) { 2162ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov try { 2163385de624aa990266ffbaf70711ac8a330569429eFyodor Kupolov return mService.getUserCreationTime(userHandle.getIdentifier()); 2164ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov } catch (RemoteException re) { 2165f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 2166ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov } 2167ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov } 216812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 216912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 217012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 217112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Checks if any uninitialized user has the specific seed account name and type. 217212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * 217312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param mAccountName The account name to check for 217412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param mAccountType The account type of the account to check for 217512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @return whether the seed account was found 217612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 217712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public boolean someUserHasSeedAccount(String accountName, String accountType) { 217812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani try { 217912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani return mService.someUserHasSeedAccount(accountName, accountType); 218012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } catch (RemoteException re) { 2181f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey throw re.rethrowFromSystemServer(); 218212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 218312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 2184258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani} 2185