UserManager.java revision 27b2e6978716f9886db40f4fcf2e060b50637ac5
1258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/* 2258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Copyright (C) 2012 The Android Open Source Project 3258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 4258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Licensed under the Apache License, Version 2.0 (the "License"); 5258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * you may not use this file except in compliance with the License. 6258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * You may obtain a copy of the License at 7258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 8258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * http://www.apache.org/licenses/LICENSE-2.0 9258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 10258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Unless required by applicable law or agreed to in writing, software 11258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * distributed under the License is distributed on an "AS IS" BASIS, 12258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * See the License for the specific language governing permissions and 14258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * limitations under the License. 15258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 16258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipackage android.os; 17258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 18b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chenimport android.Manifest; 1902cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolovimport android.accounts.AccountManager; 207cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chenimport android.annotation.Nullable; 21b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chenimport android.annotation.RequiresPermission; 220e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasaniimport android.annotation.SystemApi; 238588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkeyimport android.annotation.UserIdInt; 2437ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasaniimport android.app.Activity; 25409297da182267465adbc21cfb75a23e8d678117Dianne Hackbornimport android.app.ActivityManager; 26a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackbornimport android.app.ActivityManagerNative; 27cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolovimport android.app.admin.DevicePolicyManager; 28068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onukiimport android.content.ComponentName; 29258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.Context; 3012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasaniimport android.content.Intent; 31258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.pm.UserInfo; 3227bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkeyimport android.content.res.Resources; 336794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport android.graphics.Bitmap; 341bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roosimport android.graphics.BitmapFactory; 354f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.Rect; 364f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.drawable.Drawable; 375b0e5207e1b2de9fd533fa444b8d9a0acadd1513Jeff Sharkeyimport android.os.storage.StorageManager; 381e9c21871e81642669079cd290ef47818a3165bdAmith Yamasaniimport android.provider.Settings; 391c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monkimport android.view.WindowManager.LayoutParams; 40258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 416794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport com.android.internal.R; 426794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 431bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roosimport java.io.IOException; 444f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport java.util.ArrayList; 45258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport java.util.List; 46258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 47258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/** 48258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Manages users and user details on a multi-user system. 49258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 50258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipublic class UserManager { 51258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 52258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani private static String TAG = "UserManager"; 53258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani private final IUserManager mService; 54258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani private final Context mContext; 55258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 56e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 5753019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov * Specifies if a user is disallowed from adding and removing accounts, unless they are 5853019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov * {@link android.accounts.AccountManager#addAccountExplicitly programmatically} added by 5953019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov * Authenticator. 6071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 6126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 62b6c0ce4ac915cd5ab9a308cb0a4861c4e2cd7dfbBenjamin Franz * <p>From {@link android.os.Build.VERSION_CODES#N} a profile or device owner app can still 63b6c0ce4ac915cd5ab9a308cb0a4861c4e2cd7dfbBenjamin Franz * use {@link android.accounts.AccountManager} APIs to add or remove accounts when account 64b6c0ce4ac915cd5ab9a308cb0a4861c4e2cd7dfbBenjamin Franz * management is disallowed. 65b6c0ce4ac915cd5ab9a308cb0a4861c4e2cd7dfbBenjamin Franz * 660ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 670ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 68068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 69068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 70e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 71e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 7271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts"; 73e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 74e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 7526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from changing Wi-Fi 762cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds * access points. The default value is <code>false</code>. 770ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect in a managed profile. 7826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 790ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 800ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 81068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 82068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 83e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 84e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 8571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi"; 86e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 87e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 8826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from installing applications. 8971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 9026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 910ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 920ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 93068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 94068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 95e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 96e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 9771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_INSTALL_APPS = "no_install_apps"; 98e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 99e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 10026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from uninstalling applications. 10171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 10226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 1030ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1040ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 105068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 106068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 107e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 108e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 10971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps"; 110e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 11171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 112150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * Specifies if a user is disallowed from turning on location sharing. 11371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 1140ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>In a managed profile, location sharing always reflects the primary user's setting, but 115150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * can be overridden and forced off by setting this restriction to true in the managed profile. 11626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 1170ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1180ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 119068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 120068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 1216794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall * @see #getUserRestrictions() 1226794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall */ 12371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_SHARE_LOCATION = "no_share_location"; 1246794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 125a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 12626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from enabling the 127a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * "Unknown Sources" setting, that allows installation of apps from unknown sources. 128a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * The default value is <code>false</code>. 12926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 1300ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1310ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 132068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 133068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 134a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #getUserRestrictions() 135a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 136a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources"; 137a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 138a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 13926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring bluetooth. 1401c4c442e4540b16aed7acc345aea26ab101efbf8Nicolas Prevot * This does <em>not</em> restrict the user from turning bluetooth on or off. 141a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * The default value is <code>false</code>. 1420ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect in a managed profile. 14326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 1440ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1450ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 146068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 147068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 148a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #getUserRestrictions() 149a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 150a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth"; 151a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 152a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 15326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from transferring files over 154c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * USB. This can only be set by device owners and profile owners on the primary user. 155c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 15626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 1570ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1580ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 159068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 160068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 161a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #getUserRestrictions() 162a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 163a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer"; 164a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 165b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier /** 16626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring user 167b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * credentials. The default value is <code>false</code>. 16826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 1690ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1700ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 171068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 172068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 173b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * @see #getUserRestrictions() 174b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier */ 175b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials"; 176b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier 177b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier /** 178150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * When set on the primary user this specifies if the user can remove other users. 179150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * When set on a secondary user, this specifies if the user can remove itself. 180150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * This restriction has no effect on managed profiles. 181150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * The default value is <code>false</code>. 18226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 1830ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1840ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 185068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 186068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 187b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * @see #getUserRestrictions() 188b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier */ 189b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier public static final String DISALLOW_REMOVE_USER = "no_remove_user"; 190b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier 191d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 19226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from enabling or 193d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * accessing debugging features. The default value is <code>false</code>. 19426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 1950ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 1960ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 197068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 198068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 199d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 200d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 201d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features"; 202d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 203d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 20426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring VPN. 205d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * The default value is <code>false</code>. 206298f98fa234f353267ddc9c75d58e8cc542c25f1Nicolas Prevot * This restriction has an effect in a managed profile only from 2070e3de6cacaffcfeda4d6353be61e2f1f9ed80705Dianne Hackborn * {@link android.os.Build.VERSION_CODES#M} 20826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 2090ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 2100ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 211068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 212068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 213d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 214d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 215d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_CONFIG_VPN = "no_config_vpn"; 216d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 217d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 21826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring Tethering 219c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * & portable hotspots. This can only be set by device owners and profile owners on the 220c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * primary user. The default value is <code>false</code>. 22126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 2220ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 2230ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 224068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 225068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 226d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 227d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 228d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering"; 229d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 230d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 231e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * Specifies if a user is disallowed from resetting network settings 232e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * from Settings. This can only be set by device owners and profile owners on the primary user. 233e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * The default value is <code>false</code>. 2340ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect on secondary users and managed profiles since only the 235e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * primary user can reset the network settings of the device. 236e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * 2370ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 2380ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 239068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 240068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 241e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * @see #getUserRestrictions() 242e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott */ 243e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott public static final String DISALLOW_NETWORK_RESET = "no_network_reset"; 244e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott 245e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott /** 24626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from factory resetting 247c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * from Settings. This can only be set by device owners and profile owners on the primary user. 248c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 2490ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect on secondary users and managed profiles since only the 250150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * primary user can factory reset the device. 25126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 2520ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 2530ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 254068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 255068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 256d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 257d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 258d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_FACTORY_RESET = "no_factory_reset"; 259d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 260d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 26126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from adding new users and 262c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * profiles. This can only be set by device owners and profile owners on the primary user. 263c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 2640ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect on secondary users and managed profiles since only the 265150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * primary user can add other users. 26626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 2670ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 2680ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 269068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 270068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 271d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 272d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 273d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_ADD_USER = "no_add_user"; 274d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 275d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 27626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from disabling application 277d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * verification. The default value is <code>false</code>. 27826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 2790ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 2800ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 281068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 282068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 283d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 284d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 285d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps"; 286d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 287d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 28826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring cell 289c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * broadcasts. This can only be set by device owners and profile owners on the primary user. 290c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 2910ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect on secondary users and managed profiles since only the 292150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * primary user can configure cell broadcasts. 29326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 2940ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 2950ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 296068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 297068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 298d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 299d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 300d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts"; 301d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 302d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 30326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring mobile 304c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * networks. This can only be set by device owners and profile owners on the primary user. 305c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 3060ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>This restriction has no effect on secondary users and managed profiles since only the 307150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * primary user can configure mobile networks. 30826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 3090ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 3100ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 311068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 312068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 313d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 314d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 315d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks"; 316d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 317d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 31826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from modifying 319c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * applications in Settings or launchers. The following actions will not be allowed when this 320c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * restriction is enabled: 321c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>uninstalling apps</li> 322c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>disabling apps</li> 323c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>clearing app caches</li> 324c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>clearing app data</li> 325c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>force stopping apps</li> 326c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>clearing app defaults</li> 327c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <p> 328c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * The default value is <code>false</code>. 32926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 3300ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 3310ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 332068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 333068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 334d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 335d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 33636fbc8d6453da438a8ab83352ff1bcfcba5f25b5Julia Reynolds public static final String DISALLOW_APPS_CONTROL = "no_control_apps"; 337d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 338394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier /** 33926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from mounting 340c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * physical external media. This can only be set by device owners and profile owners on the 341c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * primary user. The default value is <code>false</code>. 34226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 3430ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 3440ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 345068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 346068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 347394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier * @see #getUserRestrictions() 348394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier */ 349394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media"; 350394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier 351394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier /** 35226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from adjusting microphone 353c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * volume. If set, the microphone will be muted. This can only be set by device owners 354c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * and profile owners on the primary user. The default value is <code>false</code>. 35526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 3560ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 3570ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 358068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 359068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 360394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier * @see #getUserRestrictions() 361394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier */ 362394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone"; 363394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier 364394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier /** 36526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from adjusting the master 366c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * volume. If set, the master volume will be muted. This can only be set by device owners 367c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * and profile owners on the primary user. The default value is <code>false</code>. 36826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 3690ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 3700ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 371068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 372068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 373394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier * @see #getUserRestrictions() 374394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier */ 375394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume"; 376394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier 3779f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani /** 37826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies that the user is not allowed to make outgoing 379390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani * phone calls. Emergency calls are still permitted. 380390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani * The default value is <code>false</code>. 381eb83ab52b28766adf1743db76484515bc9b9e08aTony Mak * <p>This restriction has no effect on managed profiles. 38226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 3830ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 3840ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 385068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 386068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 387390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani * @see #getUserRestrictions() 388390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani */ 389390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls"; 390390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani 391390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani /** 39226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies that the user is not allowed to send or receive 393c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * SMS messages. The default value is <code>false</code>. 39426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 3950ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 3960ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 397068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 398068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 3999f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani * @see #getUserRestrictions() 4009f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani */ 401390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani public static final String DISALLOW_SMS = "no_sms"; 4029f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani 4031c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk /** 4042cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * Specifies if the user is not allowed to have fun. In some cases, the 4052cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * device owner may wish to prevent the user from experiencing amusement or 4062cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * joy while using the device. The default value is <code>false</code>. 4072cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * 4080ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 4090ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 410068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 411068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 4122cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * @see #getUserRestrictions() 4132cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey */ 4142cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey public static final String DISALLOW_FUN = "no_fun"; 4152cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey 4162cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey /** 41726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies that windows besides app windows should not be 4181c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * created. This will block the creation of the following types of windows. 4191c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_TOAST}</li> 4201c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_PHONE}</li> 4211c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li> 4221c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li> 4231c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li> 4241c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li> 4251c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * 426c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * <p>This can only be set by device owners and profile owners on the primary user. 427c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 42826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 4290ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 4300ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 431068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 432068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 4331c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * @see #getUserRestrictions() 4341c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk */ 4351c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows"; 4361c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk 437f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot /** 43826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if what is copied in the clipboard of this profile can 439f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be 440f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot * pasted in this profile. 441f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot * 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) 447f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot * @see #getUserRestrictions() 448f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot */ 449f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste"; 450f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot 45126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani /** 45226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if the user is not allowed to use NFC to beam out data from apps. 45326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * The default value is <code>false</code>. 45426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 4550ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 4560ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 457068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 458068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 45926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * @see #getUserRestrictions() 46026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani */ 46126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam"; 46226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani 46353d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse /** 464f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * Hidden user restriction to disallow access to wallpaper manager APIs. This restriction 465f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * generally means that wallpapers are not supported for the particular user. This user 466f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * restriction is always set for managed profiles, because such profiles don't have wallpapers. 467f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz * @hide 468f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * @see #DISALLOW_SET_WALLPAPER 469068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 470068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 471f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz * @see #getUserRestrictions() 472f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz */ 473f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz public static final String DISALLOW_WALLPAPER = "no_wallpaper"; 474f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz 475f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz /** 476f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * User restriction to disallow setting a wallpaper. Profile owner and device owner 477f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * are able to set wallpaper regardless of this restriction. 478f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * The default value is <code>false</code>. 479f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * 480f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * <p>Key for user restrictions. 481f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * <p>Type: Boolean 482f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 483f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 484f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi * @see #getUserRestrictions() 485f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi */ 486f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi public static final String DISALLOW_SET_WALLPAPER = "no_set_wallpaper"; 487f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi 488f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi /** 489bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * Specifies if the user is not allowed to reboot the device into safe boot mode. 490bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * This can only be set by device owners and profile owners on the primary user. 491bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * The default value is <code>false</code>. 492bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * 4930ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 4940ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 495068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 496068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 497bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * @see #getUserRestrictions() 498bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz */ 499bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz public static final String DISALLOW_SAFE_BOOT = "no_safe_boot"; 500bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz 501bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz /** 502b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov * Specifies if a user is not allowed to record audio. This restriction is always enabled for 503b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov * background users. The default value is <code>false</code>. 504b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov * 505068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 506068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 507b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov * @see #getUserRestrictions() 508b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov * @hide 509b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov */ 510b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov public static final String DISALLOW_RECORD_AUDIO = "no_record_audio"; 511b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov 512b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov /** 5139cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * Specifies if a user is not allowed to run in the background and should be stopped during 5149cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * user switch. The default value is <code>false</code>. 5159cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * 5169cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * <p>This restriction can be set by device owners and profile owners. 5179cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * 5189cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 5199cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 5209cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * @see #getUserRestrictions() 5219cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov * @hide 5229cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov */ 5239cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov public static final String DISALLOW_RUN_IN_BACKGROUND = "no_run_in_background"; 5249cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov 5259cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov /** 526759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * Specifies if a user is not allowed to use the camera. 527759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * 528759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 529759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 530759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * @see #getUserRestrictions() 531759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * @hide 532759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki */ 533759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki public static final String DISALLOW_CAMERA = "no_camera"; 534759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki 535759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki /** 536dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra * Specifies if a user is not allowed to use cellular data when roaming. This can only be set by 537dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra * device owners. The default value is <code>false</code>. 538dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra * 539dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 540dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 541dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra * @see #getUserRestrictions() 542dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra */ 543dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra public static final String DISALLOW_DATA_ROAMING = "no_data_roaming"; 544dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra 545dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra /** 5467f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * Specifies if a user is not allowed to change their icon. Device owner and profile owner 5477f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * can set this restriction. When it is set by device owner, only the target user will be 5487f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * affected. The default value is <code>false</code>. 5497f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * 5507f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * <p>Key for user restrictions. 5517f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * <p>Type: Boolean 5527f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 5537f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 5547f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi * @see #getUserRestrictions() 5557f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi */ 5567f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi public static final String DISALLOW_SET_USER_ICON = "no_set_user_icon"; 5577f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi 5587f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi /** 559f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot * Allows apps in the parent profile to handle web links from the managed profile. 560f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot * 5619edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * This user restriction has an effect only in a managed profile. 5629edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * If set: 5639edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * Intent filters of activities in the parent profile with action 5649edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * {@link android.content.Intent#ACTION_VIEW}, 5659edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which 5669edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * define a host can handle intents from the managed profile. 5679edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * The default value is <code>false</code>. 5689edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * 5690ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for user restrictions. 5700ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 571068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 572068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 5739edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * @see #getUserRestrictions() 5749edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot */ 575f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot public static final String ALLOW_PARENT_PROFILE_APP_LINKING 576f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot = "allow_parent_profile_app_linking"; 5779edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot 5789edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot /** 57953d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * Application restriction key that is used to indicate the pending arrival 58053d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * of real restrictions for the app. 58153d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * 58253d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * <p> 58353d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * Applications that support restrictions should check for the presence of this key. 58453d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * A <code>true</code> value indicates that restrictions may be applied in the near 58553d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * future but are not available yet. It is the responsibility of any 58653d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * management application that sets this flag to update it when the final 58753d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * restrictions are enforced. 58853d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * 5890ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Key for application restrictions. 5900ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov * <p>Type: Boolean 591b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions( 592b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot * android.content.ComponentName, String, Bundle) 593b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions( 594b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot * android.content.ComponentName, String) 59553d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse */ 59653d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending"; 59753d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse 59812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani private static final String ACTION_CREATE_USER = "android.os.action.CREATE_USER"; 59912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 60012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 60112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Extra containing a name for the user being created. Optional parameter passed to 60212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * ACTION_CREATE_USER activity. 60312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 60412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 60512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public static final String EXTRA_USER_NAME = "android.os.extra.USER_NAME"; 60612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 60712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 60812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Extra containing account name for the user being created. Optional parameter passed to 60912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * ACTION_CREATE_USER activity. 61012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 61112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 61212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public static final String EXTRA_USER_ACCOUNT_NAME = "android.os.extra.USER_ACCOUNT_NAME"; 61312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 61412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 61512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Extra containing account type for the user being created. Optional parameter passed to 61612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * ACTION_CREATE_USER activity. 61712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 61812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 61912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public static final String EXTRA_USER_ACCOUNT_TYPE = "android.os.extra.USER_ACCOUNT_TYPE"; 62012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 62112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 62212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Extra containing account-specific data for the user being created. Optional parameter passed 62312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * to ACTION_CREATE_USER activity. 62412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 62512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 62612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public static final String EXTRA_USER_ACCOUNT_OPTIONS 62712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani = "android.os.extra.USER_ACCOUNT_OPTIONS"; 62812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 629655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** @hide */ 630655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3; 631655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** @hide */ 632655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2; 633655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** @hide */ 634655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani public static final int PIN_VERIFICATION_SUCCESS = -1; 635655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani 63637ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani /** 63737ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * Error result indicating that this user is not allowed to add other users on this device. 63837ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * This is a result code returned from the activity created by the intent 63937ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}. 64037ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani */ 64137ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani public static final int USER_CREATION_FAILED_NOT_PERMITTED = Activity.RESULT_FIRST_USER; 64237ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani 64337ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani /** 64437ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * Error result indicating that no more users can be created on this device. 64537ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * This is a result code returned from the activity created by the intent 64637ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}. 64737ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani */ 64837ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani public static final int USER_CREATION_FAILED_NO_MORE_USERS = Activity.RESULT_FIRST_USER + 1; 64937ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani 6507e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani /** @hide */ 651c0688301de5feea94c8456b3b9b42c41d0045f03Amith Yamasani public static UserManager get(Context context) { 652c0688301de5feea94c8456b3b9b42c41d0045f03Amith Yamasani return (UserManager) context.getSystemService(Context.USER_SERVICE); 65327db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani } 654a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 655258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** @hide */ 656258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public UserManager(Context context, IUserManager service) { 657258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mService = service; 658258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mContext = context; 659258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 660258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 661258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 662258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns whether the system supports multiple users. 6631a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy * @return true if multiple users can be created by user, false if it is a single user device. 664e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * @hide 665258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 6664673e7ea8d1f869910a9c0f9c211d4d27ad50b41Jeff Sharkey public static boolean supportsMultipleUsers() { 6671a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy return getMaxSupportedUsers() > 1 6681a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy && SystemProperties.getBoolean("fw.show_multiuserui", 6691a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI)); 670258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 671258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 6726794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall /** 6737cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen * @hide 6747cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen * @return Whether the device is running with split system user. It means the system user and 6757cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen * primary user are two separate users. Previously system user and primary user are combined as 6767cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen * a single owner user. see @link {android.os.UserHandle#USER_OWNER} 6777cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen */ 6787cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen public static boolean isSplitSystemUser() { 6797cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen return SystemProperties.getBoolean("ro.fw.system_user_split", false); 6807cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen } 6817cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen 6827cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen /** 6835760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * Returns the user handle for the user that this process is running under. 684be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * 6855760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * @return the user handle of this process. 686258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 6876794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall */ 6888588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public @UserIdInt int getUserHandle() { 68979af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn return UserHandle.myUserId(); 690258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 691258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 692258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 6938832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn * Returns the user name of the user making this call. This call is only 6948832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn * available to applications on the system image; it requires the 6958832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn * MANAGE_USERS permission. 696258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the user name 697258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 698258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public String getUserName() { 699258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 700258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.getUserInfo(getUserHandle()).name; 701258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 70227b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 703258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 704258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 705258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 70667a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn /** 707e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill * Used to determine whether the user making this call is subject to 708e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill * teleportations. 70967a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn * 710955d8d69ea6caabce1461dc25b339b9bf9dc61a6Dianne Hackborn * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can 71167a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn * now automatically identify goats using advanced goat recognition technology.</p> 71267a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn * 71367a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn * @return Returns true if the user making this call is a goat. 714e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill */ 715e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill public boolean isUserAGoat() { 716988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell return mContext.getPackageManager() 717988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell .isPackageAvailable("com.coffeestainstudios.goatsimulator"); 718e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill } 719df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 720df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani /** 72170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * Used to check if this process is running under the primary user. The primary user 72270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * is the first human user on a device. 72370f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * 72470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * @return whether this process is running under the primary user. 72570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * @hide 72670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen */ 72770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen public boolean isPrimaryUser() { 72870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen UserInfo user = getUserInfo(UserHandle.myUserId()); 72970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen return user != null ? user.isPrimary() : false; 73070f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen } 73170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen 73270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen /** 7335760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * Used to check if this process is running under the system user. The system user 7345760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * is the initial user that is implicitly created on first boot and hosts most of the 7355760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * system services. 7365760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * 7375760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * @return whether this process is running under the system user. 7385760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani */ 7395760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani public boolean isSystemUser() { 74070f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen return UserHandle.myUserId() == UserHandle.USER_SYSTEM; 7415760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani } 7422b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen 7435760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani /** 744462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani * @hide 745462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani * Returns whether the caller is running as an admin user. There can be more than one admin 746462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani * user. 747462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani */ 748462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani public boolean isAdminUser() { 7492b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen return isUserAdmin(UserHandle.myUserId()); 7502b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen } 7512b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen 7522b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen /** 7532b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen * @hide 7542b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen * Returns whether the provided user is an admin user. There can be more than one admin 7552b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen * user. 7562b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen */ 7578588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean isUserAdmin(@UserIdInt int userId) { 7582b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen UserInfo user = getUserInfo(userId); 7592b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen return user != null && user.isAdmin(); 760462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani } 761462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani 762462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani /** 763e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani * Used to check if the user making this call is linked to another user. Linked users may have 76446bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani * a reduced number of available apps, app restrictions and account restrictions. 765e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani * @return whether the user making this call is a linked user 7662555dafce87e60fae28d71913730abf73e40fcd7Amith Yamasani * @hide 767df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani */ 768e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani public boolean isLinkedUser() { 769df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani try { 77071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani return mService.isRestricted(); 771df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } catch (RemoteException re) { 77227b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 773df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 774df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 775df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 776258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 7771c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov * Checks if specified user can have restricted profile. 7781c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov * @hide 7791c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov */ 7808588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean canHaveRestrictedProfile(@UserIdInt int userId) { 7811c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov try { 7821c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov return mService.canHaveRestrictedProfile(userId); 7831c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov } catch (RemoteException re) { 78427b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 7851c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov } 7861c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov } 7871c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov 7881c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov /** 7891e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * Checks if the calling app is running as a guest user. 7901e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * @return whether the caller is a guest user. 7911e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * @hide 7921e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani */ 7931e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani public boolean isGuestUser() { 7941e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani UserInfo user = getUserInfo(UserHandle.myUserId()); 7951e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani return user != null ? user.isGuest() : false; 7961e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani } 7971e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani 7981e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani /** 7990e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani * Checks if the calling app is running in a managed profile. 8000e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 8010e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani * 8020e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani * @return whether the caller is in a managed profile. 8030e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani * @hide 8040e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani */ 8050e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani @SystemApi 8060e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani public boolean isManagedProfile() { 8070e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani UserInfo user = getUserInfo(UserHandle.myUserId()); 8080e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani return user != null ? user.isManagedProfile() : false; 8090e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani } 8100e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani 8110e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani /** 812c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova * Checks if the calling app is running as an ephemeral user. 813c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova * 814c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova * @return whether the caller is an ephemeral user. 815c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova * @hide 816c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova */ 817c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova public boolean isEphemeralUser() { 818c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova return isUserEphemeral(UserHandle.myUserId()); 819c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova } 820c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova 821c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova /** 822c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova * Returns whether the specified user is ephemeral. 823c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova * @hide 824c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova */ 8258588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean isUserEphemeral(@UserIdInt int userId) { 826c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova final UserInfo user = getUserInfo(userId); 827c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova return user != null && user.isEphemeral(); 828c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova } 829c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova 830c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova /** 831a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * Return whether the given user is actively running. This means that 832a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * the user is in the "started" state, not "stopped" -- it is currently 833a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * allowed to run code through scheduled alarms, receiving broadcasts, 834a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * etc. A started user may be either the current foreground user or a 835a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * background user; the result here does not distinguish between the two. 836a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * @param user The user to retrieve the running state for. 837a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn */ 838a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn public boolean isUserRunning(UserHandle user) { 8390e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey return isUserRunning(user.getIdentifier()); 8400e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey } 8410e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey 8420e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey /** {@hide} */ 8430e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey public boolean isUserRunning(int userId) { 844a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn try { 8450e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey return ActivityManagerNative.getDefault().isUserRunning(userId, 0); 84627b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 84727b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 848a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 849a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 850a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn 851a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn /** 852a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * Return whether the given user is actively running <em>or</em> stopping. 853a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * This is like {@link #isUserRunning(UserHandle)}, but will also return 854a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * true if the user had been running but is in the process of being stopped 855a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * (but is not yet fully stopped, and still running some code). 856a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * @param user The user to retrieve the running state for. 857a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn */ 858a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn public boolean isUserRunningOrStopping(UserHandle user) { 859a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn try { 860e17ac1569793c333bb4dce86607a342e7c982ae7Jeff Sharkey // TODO: reconcile stopped vs stopping? 861a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn return ActivityManagerNative.getDefault().isUserRunning( 862e17ac1569793c333bb4dce86607a342e7c982ae7Jeff Sharkey user.getIdentifier(), ActivityManager.FLAG_OR_STOPPED); 86327b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 86427b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 865a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 866a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 867a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn 868a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn /** 869e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey * Return whether the calling user is running in a "locked" state. A user is 870e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey * unlocked only after they've entered their credentials (such as a lock 871e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey * pattern or PIN), and credential-encrypted private app data storage is 872e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey * available. 873e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey */ 874b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey @Deprecated 875e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey public boolean isUserRunningAndLocked() { 876e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey return isUserRunningAndLocked(Process.myUserHandle()); 877e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey } 878e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey 879e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey /** 8809d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey * Return whether the given user is running in a "locked" state. A user 8819d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey * is unlocked only after they've entered their credentials (such as a lock 8829d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey * pattern or PIN), and credential-encrypted private app data storage is 8839d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey * available. 8849d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey * 8859d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey * @param user to retrieve the unlocked state for. 8869d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey */ 887b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey @Deprecated 8889d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey public boolean isUserRunningAndLocked(UserHandle user) { 8899d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey try { 8909d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey return ActivityManagerNative.getDefault().isUserRunning( 8919d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey user.getIdentifier(), ActivityManager.FLAG_AND_LOCKED); 89227b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 89327b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 8949d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey } 8959d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey } 8969d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey 8979d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey /** 898e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey * Return whether the calling user is running in an "unlocked" state. A user 899e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey * is unlocked only after they've entered their credentials (such as a lock 900e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey * pattern or PIN), and credential-encrypted private app data storage is 901e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey * available. 902e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey */ 903b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey @Deprecated 904e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey public boolean isUserRunningAndUnlocked() { 905e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey return isUserRunningAndUnlocked(Process.myUserHandle()); 906e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey } 907e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey 908e13529a4adb60e5a18c2e36ce6c5bf8f2d1db78fJeff Sharkey /** 9090825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey * Return whether the given user is running in an "unlocked" state. A user 9100825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey * is unlocked only after they've entered their credentials (such as a lock 9110825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey * pattern or PIN), and credential-encrypted private app data storage is 9120825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey * available. 9130825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey * 9140825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey * @param user to retrieve the unlocked state for. 9150825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey */ 916b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey @Deprecated 9179d8a1048bb666c68402dce031bebfa07c92a42dbJeff Sharkey public boolean isUserRunningAndUnlocked(UserHandle user) { 9180825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey try { 9190825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey return ActivityManagerNative.getDefault().isUserRunning( 9200825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey user.getIdentifier(), ActivityManager.FLAG_AND_UNLOCKED); 92127b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 92227b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 9230825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey } 9240825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey } 9250825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey 9260825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey /** 927b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey * Return whether the calling user is running in an "unlocked" state. A user 928b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey * is unlocked only after they've entered their credentials (such as a lock 929b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey * pattern or PIN), and credential-encrypted private app data storage is 930b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey * available. 931b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey */ 932b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey public boolean isUserUnlocked() { 933b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey return isUserUnlocked(Process.myUserHandle()); 934b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey } 935b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey 936b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey /** 937b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey * Return whether the given user is running in an "unlocked" state. A user 938b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey * is unlocked only after they've entered their credentials (such as a lock 939b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey * pattern or PIN), and credential-encrypted private app data storage is 940b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey * available. 941b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey * 942b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey * @param user to retrieve the unlocked state for. 943b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey */ 944b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey public boolean isUserUnlocked(UserHandle user) { 9450999c0d6e9c83873d9595ee764b6388dbc49dcb8Jeff Sharkey return isUserUnlocked(user.getIdentifier()); 9460999c0d6e9c83873d9595ee764b6388dbc49dcb8Jeff Sharkey } 9470999c0d6e9c83873d9595ee764b6388dbc49dcb8Jeff Sharkey 9480999c0d6e9c83873d9595ee764b6388dbc49dcb8Jeff Sharkey /** {@hide} */ 9498588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean isUserUnlocked(@UserIdInt int userId) { 9505b0e5207e1b2de9fd533fa444b8d9a0acadd1513Jeff Sharkey // TODO: eventually pivot this back to look at ActivityManager state, 9515b0e5207e1b2de9fd533fa444b8d9a0acadd1513Jeff Sharkey // but there is race where we can start a non-encryption-aware launcher 9525b0e5207e1b2de9fd533fa444b8d9a0acadd1513Jeff Sharkey // before that lifecycle has entered the running unlocked state. 9535b0e5207e1b2de9fd533fa444b8d9a0acadd1513Jeff Sharkey return mContext.getSystemService(StorageManager.class).isUserKeyUnlocked(userId); 954b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey } 955b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey 956b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey /** 957258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns the UserInfo object describing a specific user. 9581952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 959258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the user handle of the user whose information is being requested. 960258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the UserInfo object for a specific user. 961258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 962b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn */ 9638588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public UserInfo getUserInfo(@UserIdInt int userHandle) { 964258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 965258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.getUserInfo(userHandle); 966258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 96727b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 968258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 969258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 970258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 97171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 97271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Returns the user-wide restrictions imposed on this user. 97371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @return a Bundle containing all the restrictions. 97471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 975e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public Bundle getUserRestrictions() { 976e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani return getUserRestrictions(Process.myUserHandle()); 977e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 978e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 97971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 98071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>. 98171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 98271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @return a Bundle containing all the restrictions. 98371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 984e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public Bundle getUserRestrictions(UserHandle userHandle) { 985e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani try { 986e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani return mService.getUserRestrictions(userHandle.getIdentifier()); 987e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } catch (RemoteException re) { 98827b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 989e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 990e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 991e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 9923bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban /** 9933bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban * @hide 9943bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban * Returns whether the given user has been disallowed from performing certain actions 9953bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban * or setting certain settings through UserManager. This method disregards restrictions 9963bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban * set by device policy. 9973bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban * @param restrictionKey the string key representing the restriction 9983bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 9993bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban */ 10003bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban public boolean hasBaseUserRestriction(String restrictionKey, UserHandle userHandle) { 10013bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban try { 10023bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban return mService.hasBaseUserRestriction(restrictionKey, userHandle.getIdentifier()); 10033bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban } catch (RemoteException re) { 100427b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 10053bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban } 10063bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban } 10073bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban 100871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 1009a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki * This will no longer work. Device owners and profile owners should use 1010a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead. 101171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 1012a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki // System apps should use UserManager.setUserRestriction() instead. 10133d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds @Deprecated 1014e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public void setUserRestrictions(Bundle restrictions) { 1015068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki throw new UnsupportedOperationException("This method is no longer supported"); 1016e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 1017e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 101871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 1019a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki * This will no longer work. Device owners and profile owners should use 1020a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead. 102171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 1022a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki // System apps should use UserManager.setUserRestriction() instead. 10233d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds @Deprecated 1024e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) { 1025068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki throw new UnsupportedOperationException("This method is no longer supported"); 1026e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 1027e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 102871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 102971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Sets the value of a specific restriction. 1030be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani * Requires the MANAGE_USERS permission. 103171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param key the key of the restriction 103271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param value the value for the restriction 10333d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction( 10343d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * android.content.ComponentName, String)} or 10353d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * {@link android.app.admin.DevicePolicyManager#clearUserRestriction( 10363d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * android.content.ComponentName, String)} instead. 103771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 10383d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds @Deprecated 103971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public void setUserRestriction(String key, boolean value) { 1040068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki setUserRestriction(key, value, Process.myUserHandle()); 104171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani } 104271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani 104371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 104471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @hide 104571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Sets the value of a specific restriction on a specific user. 1046be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani * Requires the MANAGE_USERS permission. 104771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param key the key of the restriction 104871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param value the value for the restriction 104971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param userHandle the user whose restriction is to be changed. 10503d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction( 10513d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * android.content.ComponentName, String)} or 10523d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * {@link android.app.admin.DevicePolicyManager#clearUserRestriction( 10533d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * android.content.ComponentName, String)} instead. 105471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 10553d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds @Deprecated 10566794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall public void setUserRestriction(String key, boolean value, UserHandle userHandle) { 1057b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov try { 1058b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov mService.setUserRestriction(key, value, userHandle.getIdentifier()); 1059b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov } catch (RemoteException re) { 106027b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1061b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov } 10626794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall } 10636794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 1064258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 1065a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * Returns whether the current user has been disallowed from performing certain actions 1066a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * or setting certain settings. 10672b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds * 10682b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds * @param restrictionKey The string key representing the restriction. 10692b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds * @return {@code true} if the current user has the given restriction, {@code false} otherwise. 1070a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 1071a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public boolean hasUserRestriction(String restrictionKey) { 1072b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie return hasUserRestriction(restrictionKey, Process.myUserHandle()); 1073b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie } 1074b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie 1075b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie /** 1076b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * @hide 1077b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * Returns whether the given user has been disallowed from performing certain actions 1078b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * or setting certain settings. 1079b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * @param restrictionKey the string key representing the restriction 1080b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 1081b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie */ 1082b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) { 10838cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani try { 10848cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani return mService.hasUserRestriction(restrictionKey, 10858cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani userHandle.getIdentifier()); 10868cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani } catch (RemoteException re) { 108727b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 10888cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani } 1089a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall } 1090a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 1091a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 109233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * Return the serial number for a user. This is a device-unique 1093b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * number assigned to that user; if the user is deleted and then a new 1094b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * user created, the new users will not be given the same serial number. 109533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @param user The user whose serial number is to be retrieved. 1096b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * @return The serial number of the given user; returns -1 if the 1097b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * given UserHandle does not exist. 109833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @see #getUserForSerialNumber(long) 109933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn */ 110033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn public long getSerialNumberForUser(UserHandle user) { 110133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn return getUserSerialNumber(user.getIdentifier()); 110233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn } 110333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn 110433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn /** 110533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * Return the user associated with a serial number previously 110633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * returned by {@link #getSerialNumberForUser(UserHandle)}. 110733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @param serialNumber The serial number of the user that is being 110833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * retrieved. 110933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @return Return the user associated with the serial number, or null 111033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * if there is not one. 111133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @see #getSerialNumberForUser(UserHandle) 111233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn */ 111333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn public UserHandle getUserForSerialNumber(long serialNumber) { 1114ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov int ident = getUserHandle((int) serialNumber); 111533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn return ident >= 0 ? new UserHandle(ident) : null; 111633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn } 111733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn 111833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn /** 1119cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen * Creates a user with the specified name and options. For non-admin users, default user 1120cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen * restrictions are going to be applied. 11211952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1122258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 1123258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param name the user's name 1124258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param flags flags that identify the type of user and other properties. 1125258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @see UserInfo 1126258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 1127258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the UserInfo object for the created user, or null if the user could not be created. 1128258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1129258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 1130258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public UserInfo createUser(String name, int flags) { 1131cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen UserInfo user = null; 1132258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 1133cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen user = mService.createUser(name, flags); 1134e9c440638e27a123a82feb5e4677ce1242785288phweiss // TODO: Keep this in sync with 1135e9c440638e27a123a82feb5e4677ce1242785288phweiss // UserManagerService.LocalService.createUserEvenWhenDisallowed 1136cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen if (user != null && !user.isAdmin()) { 1137068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki mService.setUserRestriction(DISALLOW_SMS, true, user.id); 1138068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki mService.setUserRestriction(DISALLOW_OUTGOING_CALLS, true, user.id); 1139cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen } 1140258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 114127b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1142258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1143cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen return user; 1144258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1145258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 1146258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 11471e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * Creates a guest user and configures it. 11481e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * @param context an application context 11491e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * @param name the name to set for the user 11501e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * @hide 11511e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani */ 11521e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani public UserInfo createGuest(Context context, String name) { 1153068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki UserInfo guest = null; 1154068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki try { 1155068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki guest = mService.createUser(name, UserInfo.FLAG_GUEST); 1156068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki if (guest != null) { 1157068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki Settings.Secure.putStringForUser(context.getContentResolver(), 1158068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id); 1159bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani } 1160068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki } catch (RemoteException re) { 116127b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 11621e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani } 11631e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani return guest; 11641e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani } 11651e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani 1166aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani /** 11672a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * Creates a user with the specified name and options as a profile of another user. 1168a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1169a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * 1170a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @param name the user's name 1171a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @param flags flags that identify the type of user and other properties. 1172a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @see UserInfo 11732a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * @param userHandle new user will be a profile of this use. 1174a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * 1175a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @return the UserInfo object for the created user, or null if the user could not be created. 1176a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @hide 1177a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy */ 11788588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle) { 1179a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy try { 11802a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy return mService.createProfileForUser(name, flags, userHandle); 1181a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } catch (RemoteException re) { 118227b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1183a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } 1184a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } 1185a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy 1186a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy /** 118702cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov * Creates a restricted profile with the specified name. This method also sets necessary 118802cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov * restrictions and adds shared accounts. 118906a484adb93c6c969321147b07112684383305f6Fyodor Kupolov * 119006a484adb93c6c969321147b07112684383305f6Fyodor Kupolov * @param name profile's name 119106a484adb93c6c969321147b07112684383305f6Fyodor Kupolov * @return UserInfo object for the created user, or null if the user could not be created. 119206a484adb93c6c969321147b07112684383305f6Fyodor Kupolov * @hide 119306a484adb93c6c969321147b07112684383305f6Fyodor Kupolov */ 119406a484adb93c6c969321147b07112684383305f6Fyodor Kupolov public UserInfo createRestrictedProfile(String name) { 119506a484adb93c6c969321147b07112684383305f6Fyodor Kupolov try { 119602cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov UserHandle parentUserHandle = Process.myUserHandle(); 119702cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov UserInfo user = mService.createRestrictedProfile(name, 119802cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov parentUserHandle.getIdentifier()); 119902cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov if (user != null) { 120002cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov AccountManager.get(mContext).addSharedAccountsFromParentUser(parentUserHandle, 120102cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov UserHandle.of(user.id)); 120206a484adb93c6c969321147b07112684383305f6Fyodor Kupolov } 120302cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov return user; 120427b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 120527b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 120606a484adb93c6c969321147b07112684383305f6Fyodor Kupolov } 120706a484adb93c6c969321147b07112684383305f6Fyodor Kupolov } 120806a484adb93c6c969321147b07112684383305f6Fyodor Kupolov 120906a484adb93c6c969321147b07112684383305f6Fyodor Kupolov /** 121012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Returns an intent to create a user for the provided name and email address. The name 121112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * and email address will be used when the setup process for the new user is started. 121212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * If this device does not support multiple users, null is returned. 121312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * <p/> 121412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * The intent should be launched using startActivityForResult and the return result will 121537ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * indicate if the user consented to adding a new user and if the operation succeeded. Any 121637ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * errors in creating the user will be returned in the result code. If the user cancels the 121737ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * request, the return result will be {@link Activity#RESULT_CANCELED}. On success, the 121837ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * result code will be {@link Activity#RESULT_OK}. 121912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * <p/> 122012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * The new user is created but not initialized. After switching into the user for the first 122112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * time, the preferred user name and account information are used by the setup process for that 122212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * user. 122312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * 122412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param userName Optional name to assign to the user. 122512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param accountName Optional email address that will be used by the setup wizard to initialize 122612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * the user. 122712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param accountType Optional account type for the account to be created. This is required 122812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * if the account name is specified. 122912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param accountOptions Optional bundle of data to be passed in during account creation in the 123012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * new user via {@link AccountManager#addAccount(String, String, String[], 123112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Bundle, android.app.Activity, android.accounts.AccountManagerCallback, 123212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Handler)}. 123312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @return An Intent that can be launched from an Activity or null if creating users is not 123412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * supported on this device. 123537ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * @see #USER_CREATION_FAILED_NOT_PERMITTED 123637ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani * @see #USER_CREATION_FAILED_NO_MORE_USERS 123712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 123812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public static Intent createUserCreationIntent(@Nullable String userName, 123912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani @Nullable String accountName, 124012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani @Nullable String accountType, @Nullable PersistableBundle accountOptions) { 124112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani if (!supportsMultipleUsers() || getMaxSupportedUsers() < 2) { 124212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani return null; 124312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 124412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani Intent intent = new Intent(ACTION_CREATE_USER); 124512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani if (userName != null) { 124612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani intent.putExtra(EXTRA_USER_NAME, userName); 124712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 124812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani if (accountName != null && accountType == null) { 124912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani throw new IllegalArgumentException("accountType must be specified if accountName is " 125012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani + "specified"); 125112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 125212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani if (accountName != null) { 125312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani intent.putExtra(EXTRA_USER_ACCOUNT_NAME, accountName); 125412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 125512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani if (accountType != null) { 125612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani intent.putExtra(EXTRA_USER_ACCOUNT_TYPE, accountType); 125712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 125812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani if (accountOptions != null) { 125912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani intent.putExtra(EXTRA_USER_ACCOUNT_OPTIONS, accountOptions); 126012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 126112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani return intent; 126212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 126312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 126412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 126512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 126612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * 126712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Returns the preferred account name for user creation. Requires MANAGE_USERS permission. 126812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 126912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani @SystemApi 127012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public String getSeedAccountName() { 127112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani try { 127212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani return mService.getSeedAccountName(); 127312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } catch (RemoteException re) { 127427b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 127512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 127612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 127712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 127812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 127912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 128012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * 128112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Returns the preferred account type for user creation. Requires MANAGE_USERS permission. 128212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 128312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani @SystemApi 128412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public String getSeedAccountType() { 128512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani try { 128612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani return mService.getSeedAccountType(); 128712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } catch (RemoteException re) { 128827b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 128912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 129012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 129112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 129212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 129312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 129412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * 129512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Returns the preferred account's options bundle for user creation. Requires MANAGE_USERS 129612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * permission. 129712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @return Any options set by the requestor that created the user. 129812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 129912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani @SystemApi 130012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public PersistableBundle getSeedAccountOptions() { 130112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani try { 130212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani return mService.getSeedAccountOptions(); 130312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } catch (RemoteException re) { 130427b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 130512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 130612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 130712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 130812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 130912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 131012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * 131112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Called by a system activity to set the seed account information of a user created 131212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * through the user creation intent. 131312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param userId 131412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param accountName 131512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param accountType 131612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param accountOptions 131712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @see #createUserCreationIntent(String, String, String, PersistableBundle) 131812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 131912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public void setSeedAccountData(int userId, String accountName, String accountType, 132012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani PersistableBundle accountOptions) { 132112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani try { 132212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani mService.setSeedAccountData(userId, accountName, accountType, accountOptions, 132312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /* persist= */ true); 132412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } catch (RemoteException re) { 132527b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 132612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 132712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 132812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 132912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 133012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 133112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Clears the seed information used to create this user. Requires MANAGE_USERS permission. 133212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 133312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani @SystemApi 133412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public void clearSeedAccountData() { 133512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani try { 133612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani mService.clearSeedAccountData(); 133712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } catch (RemoteException re) { 133827b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 133912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 134012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 134112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 134212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 13431df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani * @hide 13441df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani * Marks the guest user for deletion to allow a new guest to be created before deleting 13451df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani * the current user who is a guest. 13461df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani * @param userHandle 13471df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani * @return 13481df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani */ 13498588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean markGuestForDeletion(@UserIdInt int userHandle) { 13501df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani try { 13511df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani return mService.markGuestForDeletion(userHandle); 13521df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani } catch (RemoteException re) { 135327b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 13541df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani } 13551df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani } 13561df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani 13571df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani /** 1358df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina * Sets the user as enabled, if such an user exists. 13591ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova * 13601ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 13611ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova * 13621ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova * <p>Note that the default is true, it's only that managed profiles might not be enabled. 13631ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova * Also ephemeral users can be disabled to indicate that their removal is in progress and they 13641ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova * shouldn't be re-entered. Therefore ephemeral users should not be re-enabled once disabled. 1365df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina * 1366df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina * @param userHandle the id of the profile to enable 1367df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina * @hide 1368df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina */ 13698588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public void setUserEnabled(@UserIdInt int userHandle) { 1370df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina try { 1371df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina mService.setUserEnabled(userHandle); 137227b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 137327b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1374df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina } 1375df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina } 1376df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina 1377df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina /** 1378b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * Return the number of users currently created on the device. 1379b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn */ 1380b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn public int getUserCount() { 1381b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn List<UserInfo> users = getUsers(); 1382b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn return users != null ? users.size() : 1; 1383b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn } 1384b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn 1385b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn /** 1386258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns information for all users on this device. 13871952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1388940e8577a1569140521fb605336997863529f7adFyodor Kupolov * @return the list of users that exist on the device. 1389258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1390258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 1391258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public List<UserInfo> getUsers() { 1392258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 1393920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani return mService.getUsers(false); 1394920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani } catch (RemoteException re) { 139527b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1396920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani } 1397920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani } 1398920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani 1399920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani /** 1400940e8577a1569140521fb605336997863529f7adFyodor Kupolov * Returns serial numbers of all users on this device. 1401940e8577a1569140521fb605336997863529f7adFyodor Kupolov * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1402940e8577a1569140521fb605336997863529f7adFyodor Kupolov * 1403940e8577a1569140521fb605336997863529f7adFyodor Kupolov * @param excludeDying specify if the list should exclude users being removed. 1404940e8577a1569140521fb605336997863529f7adFyodor Kupolov * @return the list of serial numbers of users that exist on the device. 1405940e8577a1569140521fb605336997863529f7adFyodor Kupolov * @hide 1406940e8577a1569140521fb605336997863529f7adFyodor Kupolov */ 1407940e8577a1569140521fb605336997863529f7adFyodor Kupolov @SystemApi 1408940e8577a1569140521fb605336997863529f7adFyodor Kupolov public long[] getSerialNumbersOfUsers(boolean excludeDying) { 1409940e8577a1569140521fb605336997863529f7adFyodor Kupolov try { 1410940e8577a1569140521fb605336997863529f7adFyodor Kupolov List<UserInfo> users = mService.getUsers(excludeDying); 1411940e8577a1569140521fb605336997863529f7adFyodor Kupolov long[] result = new long[users.size()]; 1412940e8577a1569140521fb605336997863529f7adFyodor Kupolov for (int i = 0; i < result.length; i++) { 1413940e8577a1569140521fb605336997863529f7adFyodor Kupolov result[i] = users.get(i).serialNumber; 1414940e8577a1569140521fb605336997863529f7adFyodor Kupolov } 1415940e8577a1569140521fb605336997863529f7adFyodor Kupolov return result; 1416940e8577a1569140521fb605336997863529f7adFyodor Kupolov } catch (RemoteException re) { 141727b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1418940e8577a1569140521fb605336997863529f7adFyodor Kupolov } 1419940e8577a1569140521fb605336997863529f7adFyodor Kupolov } 1420940e8577a1569140521fb605336997863529f7adFyodor Kupolov 1421940e8577a1569140521fb605336997863529f7adFyodor Kupolov /** 1422b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen * @return the user's account name, null if not found. 1423b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen * @hide 1424b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen */ 1425b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen @RequiresPermission( allOf = { 1426b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen Manifest.permission.INTERACT_ACROSS_USERS_FULL, 1427b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen Manifest.permission.MANAGE_USERS 1428b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen }) 14298588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public @Nullable String getUserAccount(@UserIdInt int userHandle) { 1430b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen try { 1431b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen return mService.getUserAccount(userHandle); 1432b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen } catch (RemoteException re) { 143327b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1434b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen } 1435b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen } 1436b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen 1437b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen /** 1438b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen * Set account name for the given user. 1439b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen * @hide 1440b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen */ 1441b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen @RequiresPermission( allOf = { 1442b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen Manifest.permission.INTERACT_ACROSS_USERS_FULL, 1443b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen Manifest.permission.MANAGE_USERS 1444b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen }) 14458588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public void setUserAccount(@UserIdInt int userHandle, @Nullable String accountName) { 1446b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen try { 1447b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen mService.setUserAccount(userHandle, accountName); 1448b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen } catch (RemoteException re) { 144927b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1450b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen } 1451b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen } 1452b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen 1453b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen /** 145470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * Returns information for Primary user. 145570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 145670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * 145770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * @return the Primary user, null if not found. 145870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * @hide 145970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen */ 14607cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen public @Nullable UserInfo getPrimaryUser() { 146170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen try { 146270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen return mService.getPrimaryUser(); 146370f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen } catch (RemoteException re) { 146427b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 146570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen } 146670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen } 146770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen 146870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen /** 146995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS 147095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani * permission. 147195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani * 147295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani * @return true if more users can be added, false if limit has been reached. 147395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani * @hide 147495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani */ 147595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani public boolean canAddMoreUsers() { 147695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani final List<UserInfo> users = getUsers(true); 147795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani final int totalUserCount = users.size(); 147895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani int aliveUserCount = 0; 147995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani for (int i = 0; i < totalUserCount; i++) { 148095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani UserInfo user = users.get(i); 148195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani if (!user.isGuest()) { 148295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani aliveUserCount++; 148395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani } 148495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani } 148595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani return aliveUserCount < getMaxSupportedUsers(); 148695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani } 148795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani 148895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani /** 148972434b7088591828082dd952496d523ef3622de2Nicolas Prevot * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS 149072434b7088591828082dd952496d523ef3622de2Nicolas Prevot * permission. 149107387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot * if allowedToRemoveOne is true and if the user already has a managed profile, then return if 149207387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot * we could add a new managed profile to this user after removing the existing one. 149372434b7088591828082dd952496d523ef3622de2Nicolas Prevot * 149472434b7088591828082dd952496d523ef3622de2Nicolas Prevot * @return true if more managed profiles can be added, false if limit has been reached. 149572434b7088591828082dd952496d523ef3622de2Nicolas Prevot * @hide 149672434b7088591828082dd952496d523ef3622de2Nicolas Prevot */ 14978588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean canAddMoreManagedProfiles(@UserIdInt int userId, boolean allowedToRemoveOne) { 149872434b7088591828082dd952496d523ef3622de2Nicolas Prevot try { 149907387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot return mService.canAddMoreManagedProfiles(userId, allowedToRemoveOne); 150072434b7088591828082dd952496d523ef3622de2Nicolas Prevot } catch (RemoteException re) { 150127b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 150272434b7088591828082dd952496d523ef3622de2Nicolas Prevot } 150372434b7088591828082dd952496d523ef3622de2Nicolas Prevot } 150472434b7088591828082dd952496d523ef3622de2Nicolas Prevot 150572434b7088591828082dd952496d523ef3622de2Nicolas Prevot /** 15062a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * Returns list of the profiles of userHandle including 15072a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * userHandle itself. 15084f7e2e334e4ca5f1a67baf4bdd40cd080b954161Amith Yamasani * Note that this returns both enabled and not enabled profiles. See 15097f75da2405cd910854448bb3801f776e036f926aRuben Brunk * {@link #getEnabledProfiles(int)} if you need only the enabled ones. 15104f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * 15112a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 15122a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * @param userHandle profiles of this user will be returned. 15132a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * @return the list of profiles. 15142a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * @hide 15152a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy */ 15168588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public List<UserInfo> getProfiles(@UserIdInt int userHandle) { 1517a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy try { 1518385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina return mService.getProfiles(userHandle, false /* enabledOnly */); 1519a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } catch (RemoteException re) { 152027b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1521a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } 1522a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } 1523a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy 1524a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy /** 1525fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1526fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen * @param userId one of the two user ids to check. 1527fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen * @param otherUserId one of the two user ids to check. 1528fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen * @return true if the two user ids are in the same profile group. 1529fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen * @hide 1530fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen */ 15318588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean isSameProfileGroup(@UserIdInt int userId, int otherUserId) { 1532fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen try { 1533fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen return mService.isSameProfileGroup(userId, otherUserId); 1534fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen } catch (RemoteException re) { 153527b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1536fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen } 1537fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen } 1538fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen 1539fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen /** 15407f75da2405cd910854448bb3801f776e036f926aRuben Brunk * Returns list of the profiles of userHandle including 15417f75da2405cd910854448bb3801f776e036f926aRuben Brunk * userHandle itself. 15427f75da2405cd910854448bb3801f776e036f926aRuben Brunk * Note that this returns only enabled. 15437f75da2405cd910854448bb3801f776e036f926aRuben Brunk * 15447f75da2405cd910854448bb3801f776e036f926aRuben Brunk * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 15457f75da2405cd910854448bb3801f776e036f926aRuben Brunk * @param userHandle profiles of this user will be returned. 15467f75da2405cd910854448bb3801f776e036f926aRuben Brunk * @return the list of profiles. 15477f75da2405cd910854448bb3801f776e036f926aRuben Brunk * @hide 15487f75da2405cd910854448bb3801f776e036f926aRuben Brunk */ 15498588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public List<UserInfo> getEnabledProfiles(@UserIdInt int userHandle) { 15507f75da2405cd910854448bb3801f776e036f926aRuben Brunk try { 15517f75da2405cd910854448bb3801f776e036f926aRuben Brunk return mService.getProfiles(userHandle, true /* enabledOnly */); 15527f75da2405cd910854448bb3801f776e036f926aRuben Brunk } catch (RemoteException re) { 155327b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 15547f75da2405cd910854448bb3801f776e036f926aRuben Brunk } 15557f75da2405cd910854448bb3801f776e036f926aRuben Brunk } 15567f75da2405cd910854448bb3801f776e036f926aRuben Brunk 15577f75da2405cd910854448bb3801f776e036f926aRuben Brunk /** 1558be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * Returns a list of UserHandles for profiles associated with the user that the calling process 1559be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * is running on, including the user itself. 15604f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * 15614f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * @return A non-empty list of UserHandles associated with the calling user. 15624f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani */ 15634f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani public List<UserHandle> getUserProfiles() { 15644f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani ArrayList<UserHandle> profiles = new ArrayList<UserHandle>(); 15652b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen List<UserInfo> users; 1566385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina try { 1567f2e7b3f56ae0ea9f49b5c50413b9be71d5249d6dAlexandra Gherghina users = mService.getProfiles(UserHandle.myUserId(), true /* enabledOnly */); 1568385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina } catch (RemoteException re) { 156927b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1570385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina } 15714f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani for (UserInfo info : users) { 15724f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani UserHandle userHandle = new UserHandle(info.id); 15734f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani profiles.add(userHandle); 15744f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani } 15754f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani return profiles; 15764f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani } 15774f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani 15787dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani /** 1579c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales * Returns the device credential owner id of the profile from 1580c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales * which this method is called, or userHandle if called from a user that 1581c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales * is not a profile. 1582c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales * 1583c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales * @hide 1584c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales */ 15858588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public int getCredentialOwnerProfile(@UserIdInt int userHandle) { 1586c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales try { 1587c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales return mService.getCredentialOwnerProfile(userHandle); 1588c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales } catch (RemoteException re) { 158927b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1590c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales } 1591c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales } 1592c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales 1593c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales /** 1594be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * Returns the parent of the profile which this method is called from 1595be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * or null if called from a user that is not a profile. 1596be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * 1597be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * @hide 1598be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel */ 15998588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public UserInfo getProfileParent(@UserIdInt int userHandle) { 1600be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel try { 1601be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel return mService.getProfileParent(userHandle); 1602be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel } catch (RemoteException re) { 160327b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1604be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel } 1605be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel } 1606be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel 1607be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel /** 16080a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * Set quiet mode of a managed profile. 16090a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * 16100a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * @param userHandle The user handle of the profile. 16110a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * @param enableQuietMode Whether quiet mode should be enabled or disabled. 16120a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * @hide 16130a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu */ 16148588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public void setQuietModeEnabled(@UserIdInt int userHandle, boolean enableQuietMode) { 16150a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu try { 16160a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu mService.setQuietModeEnabled(userHandle, enableQuietMode); 161727b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 161827b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 16190a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu } 16200a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu } 16210a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu 16220a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu /** 16230a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * Returns whether the given profile is in quiet mode or not. 16240a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * 16250a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * @param userHandle The user handle of the profile to be queried. 16260a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu * @return true if the profile is in quiet mode, false otherwise. 16270a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu */ 16280a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu public boolean isQuietModeEnabled(UserHandle userHandle) { 16290a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu try { 16300a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu return mService.isQuietModeEnabled(userHandle.getIdentifier()); 163127b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey } catch (RemoteException re) { 163227b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 16330a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu } 16340a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu } 16350a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu 16360a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu /** 16377dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani * If the target user is a managed profile of the calling user or the caller 16387dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani * is itself a managed profile, then this returns a badged copy of the given 1639c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * icon to be able to distinguish it from the original icon. For badging an 1640c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * arbitrary drawable use {@link #getBadgedDrawableForUser( 1641c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}. 1642c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * <p> 1643c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * If the original drawable is a BitmapDrawable and the backing bitmap is 1644c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading 1645c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * is performed in place and the original drawable is returned. 1646c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * </p> 1647c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * 1648c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param icon The icon to badge. 1649c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param user The target user. 1650c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @return A drawable that combines the original icon and a badge as 1651c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * determined by the system. 1652c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav * @removed 1653c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav */ 1654c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) { 1655c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav return mContext.getPackageManager().getUserBadgedIcon(icon, user); 1656c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav } 1657c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav 1658c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav /** 1659c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * If the target user is a managed profile of the calling user or the caller 1660c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * is itself a managed profile, then this returns a badged copy of the given 1661c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * drawable allowing the user to distinguish it from the original drawable. 1662c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * The caller can specify the location in the bounds of the drawable to be 1663c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * badged where the badge should be applied as well as the density of the 1664c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * badge to be used. 1665c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * <p> 1666c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * If the original drawable is a BitmapDrawable and the backing bitmap is 1667c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading 1668c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * is performed in place and the original drawable is returned. 1669c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * </p> 1670c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * 1671c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param badgedDrawable The drawable to badge. 1672c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param user The target user. 1673c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param badgeLocation Where in the bounds of the badged drawable to place 1674c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * the badge. If not provided, the badge is applied on top of the entire 1675c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * drawable being badged. 1676c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param badgeDensity The optional desired density for the badge as per 1677c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * {@link android.util.DisplayMetrics#densityDpi}. If not provided, 1678c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * the density of the display is used. 1679c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @return A drawable that combines the original drawable and a badge as 1680c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * determined by the system. 1681c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav * @removed 1682c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav */ 1683c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user, 1684c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav Rect badgeLocation, int badgeDensity) { 1685c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user, 1686c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav badgeLocation, badgeDensity); 16874f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani } 16884f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani 1689701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy /** 1690701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy * If the target user is a managed profile of the calling user or the caller 1691f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * is itself a managed profile, then this returns a copy of the label with 1692f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * badging for accessibility services like talkback. E.g. passing in "Email" 1693f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * and it might return "Work Email" for Email in the work profile. 1694f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * 1695f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * @param label The label to change. 1696f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * @param user The target user. 1697f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * @return A label that combines the original label and a badge as 1698f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * determined by the system. 1699c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav * @removed 1700f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy */ 1701237aecd18d0edf56c038761f570758c310c9e6dfKenny Guy public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) { 1702c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav return mContext.getPackageManager().getUserBadgedLabel(label, user); 17034f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani } 17044f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani 17054f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani /** 17064f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * Returns information for all users on this device. Requires 17074f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * {@link android.Manifest.permission#MANAGE_USERS} permission. 1708394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier * 17094f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * @param excludeDying specify if the list should exclude users being 17104f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * removed. 1711920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani * @return the list of users that were created. 1712920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani * @hide 1713920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani */ 1714920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani public List<UserInfo> getUsers(boolean excludeDying) { 1715920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani try { 1716920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani return mService.getUsers(excludeDying); 1717258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 171827b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1719258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1720258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1721258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 1722258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 1723258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Removes a user and all associated data. 17241952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1725258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the integer handle of the user, where 0 is the primary user. 1726258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1727258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 17288588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public boolean removeUser(@UserIdInt int userHandle) { 1729258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 1730258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.removeUser(userHandle); 1731258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 173227b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1733258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1734258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1735258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 1736258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 1737258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Updates the user's name. 17381952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1739258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 1740258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the user's integer handle 1741258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param name the new name for the user 1742258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1743258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 17448588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public void setUserName(@UserIdInt int userHandle, String name) { 1745258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 1746258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mService.setUserName(userHandle, name); 1747258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 174827b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1749258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1750258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1751258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 1752258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 1753e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * Sets the user's photo. 1754258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the user for whom to change the photo. 1755e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * @param icon the bitmap to set as the photo. 1756258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1757258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 17588588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public void setUserIcon(@UserIdInt int userHandle, Bitmap icon) { 1759258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 1760e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani mService.setUserIcon(userHandle, icon); 1761258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 176227b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1763258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1764258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1765258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 1766258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 17673b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani * Returns a file descriptor for the user's photo. PNG data can be read from this file. 17683b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani * @param userHandle the user whose photo we want to read. 1769e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * @return a {@link Bitmap} of the user's photo, or null if there's no photo. 177064d4dca63f65e4c7d4a829c85ff6670bdd34e2ebAlexandra Gherghina * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default. 17713b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani * @hide 17723b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani */ 17738588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public Bitmap getUserIcon(@UserIdInt int userHandle) { 17743b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani try { 17751bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos ParcelFileDescriptor fd = mService.getUserIcon(userHandle); 17761bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos if (fd != null) { 17771bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos try { 17781bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor()); 17791bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos } finally { 17801bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos try { 17811bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos fd.close(); 17821bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos } catch (IOException e) { 17831bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos } 17841bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos } 17851bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos } 17863b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani } catch (RemoteException re) { 178727b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 17883b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani } 17891bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos return null; 17903b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani } 17913b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani 17923b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani /** 1793258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns the maximum number of users that can be created on this device. A return value 1794258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * of 1 means that it is a single user device. 1795258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1796a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @return a value greater than or equal to 1 1797258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 179827bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey public static int getMaxSupportedUsers() { 1799ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani // Don't allow multiple users on certain builds 1800ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani if (android.os.Build.ID.startsWith("JVP")) return 1; 1801409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn // Svelte devices don't get multi-user. 1802409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn if (ActivityManager.isLowRamDeviceStatic()) return 1; 180327bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey return SystemProperties.getInt("fw.max_users", 180427bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers)); 1805258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 18062a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani 18072a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani /** 1808cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov * Returns true if the user switcher should be shown, this will be if device supports multi-user 1809cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov * and there are at least 2 users available that are not managed profiles. 18101a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy * @hide 18111a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy * @return true if user switcher should be shown. 18121a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy */ 18131a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy public boolean isUserSwitcherEnabled() { 1814cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov if (!supportsMultipleUsers()) { 1815cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov return false; 1816cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov } 18171a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy List<UserInfo> users = getUsers(true); 18181a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy if (users == null) { 18191a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy return false; 18201a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy } 18211a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy int switchableUserCount = 0; 18221a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy for (UserInfo user : users) { 18237cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen if (user.supportsSwitchToByUser()) { 18241a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy ++switchableUserCount; 18251a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy } 18261a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy } 1827cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class) 1828cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov .getGuestUserDisabled(null); 1829a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani return switchableUserCount > 1 || guestEnabled; 18301a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy } 18311a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy 18321a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy /** 18332a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * Returns a serial number on this device for a given userHandle. User handles can be recycled 18342a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * when deleting and creating users, but serial numbers are not reused until the device is wiped. 18352a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @param userHandle 18362a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @return a serial number associated with that user, or -1 if the userHandle is not valid. 18372a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @hide 18382a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani */ 18398588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public int getUserSerialNumber(@UserIdInt int userHandle) { 18402a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani try { 18412a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani return mService.getUserSerialNumber(userHandle); 18422a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } catch (RemoteException re) { 184327b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 18442a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 18452a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 18462a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani 18472a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani /** 18482a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * Returns a userHandle on this device for a given user serial number. User handles can be 18492a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * recycled when deleting and creating users, but serial numbers are not reused until the device 18502a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * is wiped. 18512a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @param userSerialNumber 18522a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @return the userHandle associated with that user serial number, or -1 if the serial number 18532a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * is not valid. 18542a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @hide 18552a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani */ 18568588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey public @UserIdInt int getUserHandle(int userSerialNumber) { 18572a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani try { 18582a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani return mService.getUserHandle(userSerialNumber); 18592a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } catch (RemoteException re) { 186027b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 18612a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 18622a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 18636794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 18647e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani /** 18655b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * Returns a {@code Bundle} containing any saved application restrictions for this user, for the 18667e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani * given package name. Only an application with this package name can call this method. 18675b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * 18685b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * <p>The returned {@link Bundle} consists of key-value pairs, as defined by the application, 18695b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * where the types of values may be: 18705b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * <ul> 18715b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * <li>{@code boolean} 18725b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * <li>{@code int} 18735b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * <li>{@code String} or {@code String[]} 18745b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} 18755b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * </ul> 18765b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * 18777e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani * @param packageName the package name of the calling application 18785b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * @return a {@code Bundle} with the restrictions for that package, or {@code null} if there 18795b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * are no saved restrictions. 18805b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * 18815b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera * @see #KEY_RESTRICTIONS_PENDING 18827e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani */ 18837e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani public Bundle getApplicationRestrictions(String packageName) { 18847e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani try { 18857e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani return mService.getApplicationRestrictions(packageName); 18867e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani } catch (RemoteException re) { 188727b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 18887e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani } 18897e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani } 1890df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 1891df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani /** 1892df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * @hide 1893df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani */ 18947e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani public Bundle getApplicationRestrictions(String packageName, UserHandle user) { 1895df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani try { 18967e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier()); 1897df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } catch (RemoteException re) { 189827b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1899df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 1900df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 1901df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 1902df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani /** 1903df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * @hide 1904df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani */ 19057e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani public void setApplicationRestrictions(String packageName, Bundle restrictions, 1906df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani UserHandle user) { 1907df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani try { 19087e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier()); 1909df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } catch (RemoteException re) { 191027b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1911df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 1912df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 1913655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani 1914655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** 1915d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * Sets a new challenge PIN for restrictions. This is only for use by pre-installed 1916d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * apps and requires the MANAGE_USERS permission. 1917d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * @param newPin the PIN to use for challenge dialogs. 1918d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * @return Returns true if the challenge PIN was set successfully. 1919ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov * @deprecated The restrictions PIN functionality is no longer provided by the system. 1920ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov * This method is preserved for backwards compatibility reasons and always returns false. 1921655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani */ 1922d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani public boolean setRestrictionsChallenge(String newPin) { 1923655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani return false; 1924655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani } 19251a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani 1926e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani /** 1927e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani * @hide 1928e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani * Set restrictions that should apply to any future guest user that's created. 1929e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani */ 1930e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani public void setDefaultGuestRestrictions(Bundle restrictions) { 1931e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani try { 1932e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani mService.setDefaultGuestRestrictions(restrictions); 1933e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } catch (RemoteException re) { 193427b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1935e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } 1936e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } 1937e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani 1938e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani /** 1939e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani * @hide 1940e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani * Gets the default guest restrictions. 1941e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani */ 1942e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani public Bundle getDefaultGuestRestrictions() { 1943e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani try { 1944e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani return mService.getDefaultGuestRestrictions(); 1945e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } catch (RemoteException re) { 194627b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1947e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } 1948e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } 1949ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov 1950ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov /** 1951ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov * Returns creation time of the user or of a managed profile associated with the calling user. 1952ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov * @param userHandle user handle of the user or a managed profile associated with the 1953ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov * calling user. 1954ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov * @return creation time in milliseconds since Epoch time. 1955ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov */ 1956385de624aa990266ffbaf70711ac8a330569429eFyodor Kupolov public long getUserCreationTime(UserHandle userHandle) { 1957ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov try { 1958385de624aa990266ffbaf70711ac8a330569429eFyodor Kupolov return mService.getUserCreationTime(userHandle.getIdentifier()); 1959ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov } catch (RemoteException re) { 196027b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 1961ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov } 1962ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov } 196312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani 196412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani /** 196512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @hide 196612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * Checks if any uninitialized user has the specific seed account name and type. 196712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * 196812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param mAccountName The account name to check for 196912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @param mAccountType The account type of the account to check for 197012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani * @return whether the seed account was found 197112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani */ 197212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani public boolean someUserHasSeedAccount(String accountName, String accountType) { 197312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani try { 197412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani return mService.someUserHasSeedAccount(accountName, accountType); 197512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } catch (RemoteException re) { 197627b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey throw re.rethrowAsRuntimeException(); 197712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 197812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani } 1979258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani} 1980