UserManager.java revision 4dc008cda2980fabb6acbf8a3b7096d1090ee36f
1/* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package android.os; 17 18import android.Manifest; 19import android.accounts.AccountManager; 20import android.annotation.Nullable; 21import android.annotation.RequiresPermission; 22import android.annotation.SystemApi; 23import android.annotation.UserIdInt; 24import android.app.Activity; 25import android.app.ActivityManager; 26import android.app.ActivityManagerNative; 27import android.app.admin.DevicePolicyManager; 28import android.content.ComponentName; 29import android.content.Context; 30import android.content.Intent; 31import android.content.pm.UserInfo; 32import android.content.res.Resources; 33import android.graphics.Bitmap; 34import android.graphics.BitmapFactory; 35import android.graphics.Rect; 36import android.graphics.drawable.Drawable; 37import android.os.storage.StorageManager; 38import android.provider.Settings; 39import android.telephony.TelephonyManager; 40import android.view.WindowManager.LayoutParams; 41 42import com.android.internal.R; 43 44import java.io.IOException; 45import java.util.ArrayList; 46import java.util.List; 47 48/** 49 * Manages users and user details on a multi-user system. 50 */ 51public class UserManager { 52 53 private static String TAG = "UserManager"; 54 private final IUserManager mService; 55 private final Context mContext; 56 57 /** 58 * Specifies if a user is disallowed from adding and removing accounts, unless they are 59 * {@link android.accounts.AccountManager#addAccountExplicitly programmatically} added by 60 * Authenticator. 61 * The default value is <code>false</code>. 62 * 63 * <p>From {@link android.os.Build.VERSION_CODES#N} a profile or device owner app can still 64 * use {@link android.accounts.AccountManager} APIs to add or remove accounts when account 65 * management is disallowed. 66 * 67 * <p>Key for user restrictions. 68 * <p>Type: Boolean 69 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 70 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 71 * @see #getUserRestrictions() 72 */ 73 public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts"; 74 75 /** 76 * Specifies if a user is disallowed from changing Wi-Fi 77 * access points. The default value is <code>false</code>. 78 * <p>This restriction has no effect in a managed profile. 79 * 80 * <p>Key for user restrictions. 81 * <p>Type: Boolean 82 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 83 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 84 * @see #getUserRestrictions() 85 */ 86 public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi"; 87 88 /** 89 * Specifies if a user is disallowed from installing applications. 90 * The default value is <code>false</code>. 91 * 92 * <p>Key for user restrictions. 93 * <p>Type: Boolean 94 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 95 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 96 * @see #getUserRestrictions() 97 */ 98 public static final String DISALLOW_INSTALL_APPS = "no_install_apps"; 99 100 /** 101 * Specifies if a user is disallowed from uninstalling applications. 102 * The default value is <code>false</code>. 103 * 104 * <p>Key for user restrictions. 105 * <p>Type: Boolean 106 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 107 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 108 * @see #getUserRestrictions() 109 */ 110 public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps"; 111 112 /** 113 * Specifies if a user is disallowed from turning on location sharing. 114 * The default value is <code>false</code>. 115 * <p>In a managed profile, location sharing always reflects the primary user's setting, but 116 * can be overridden and forced off by setting this restriction to true in the managed profile. 117 * 118 * <p>Key for user restrictions. 119 * <p>Type: Boolean 120 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 121 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 122 * @see #getUserRestrictions() 123 */ 124 public static final String DISALLOW_SHARE_LOCATION = "no_share_location"; 125 126 /** 127 * Specifies if a user is disallowed from enabling the 128 * "Unknown Sources" setting, that allows installation of apps from unknown sources. 129 * The default value is <code>false</code>. 130 * 131 * <p>Key for user restrictions. 132 * <p>Type: Boolean 133 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 134 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 135 * @see #getUserRestrictions() 136 */ 137 public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources"; 138 139 /** 140 * Specifies if a user is disallowed from configuring bluetooth. 141 * This does <em>not</em> restrict the user from turning bluetooth on or off. 142 * The default value is <code>false</code>. 143 * <p>This restriction has no effect in a managed profile. 144 * 145 * <p>Key for user restrictions. 146 * <p>Type: Boolean 147 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 148 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 149 * @see #getUserRestrictions() 150 */ 151 public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth"; 152 153 /** 154 * Specifies if a user is disallowed from transferring files over 155 * USB. This can only be set by device owners and profile owners on the primary user. 156 * The default value is <code>false</code>. 157 * 158 * <p>Key for user restrictions. 159 * <p>Type: Boolean 160 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 161 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 162 * @see #getUserRestrictions() 163 */ 164 public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer"; 165 166 /** 167 * Specifies if a user is disallowed from configuring user 168 * credentials. The default value is <code>false</code>. 169 * 170 * <p>Key for user restrictions. 171 * <p>Type: Boolean 172 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 173 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 174 * @see #getUserRestrictions() 175 */ 176 public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials"; 177 178 /** 179 * When set on the primary user this specifies if the user can remove other users. 180 * When set on a secondary user, this specifies if the user can remove itself. 181 * This restriction has no effect on managed profiles. 182 * The default value is <code>false</code>. 183 * 184 * <p>Key for user restrictions. 185 * <p>Type: Boolean 186 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 187 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 188 * @see #getUserRestrictions() 189 */ 190 public static final String DISALLOW_REMOVE_USER = "no_remove_user"; 191 192 /** 193 * Specifies if a user is disallowed from enabling or 194 * accessing debugging features. The default value is <code>false</code>. 195 * 196 * <p>Key for user restrictions. 197 * <p>Type: Boolean 198 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 199 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 200 * @see #getUserRestrictions() 201 */ 202 public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features"; 203 204 /** 205 * Specifies if a user is disallowed from configuring VPN. 206 * The default value is <code>false</code>. 207 * This restriction has an effect in a managed profile only from 208 * {@link android.os.Build.VERSION_CODES#M} 209 * 210 * <p>Key for user restrictions. 211 * <p>Type: Boolean 212 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 213 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 214 * @see #getUserRestrictions() 215 */ 216 public static final String DISALLOW_CONFIG_VPN = "no_config_vpn"; 217 218 /** 219 * Specifies if a user is disallowed from configuring Tethering 220 * & portable hotspots. This can only be set by device owners and profile owners on the 221 * primary user. The default value is <code>false</code>. 222 * 223 * <p>Key for user restrictions. 224 * <p>Type: Boolean 225 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 226 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 227 * @see #getUserRestrictions() 228 */ 229 public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering"; 230 231 /** 232 * Specifies if a user is disallowed from resetting network settings 233 * from Settings. This can only be set by device owners and profile owners on the primary user. 234 * The default value is <code>false</code>. 235 * <p>This restriction has no effect on secondary users and managed profiles since only the 236 * primary user can reset the network settings of the device. 237 * 238 * <p>Key for user restrictions. 239 * <p>Type: Boolean 240 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 241 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 242 * @see #getUserRestrictions() 243 */ 244 public static final String DISALLOW_NETWORK_RESET = "no_network_reset"; 245 246 /** 247 * Specifies if a user is disallowed from factory resetting 248 * from Settings. This can only be set by device owners and profile owners on the primary user. 249 * The default value is <code>false</code>. 250 * <p>This restriction has no effect on secondary users and managed profiles since only the 251 * primary user can factory reset the device. 252 * 253 * <p>Key for user restrictions. 254 * <p>Type: Boolean 255 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 256 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 257 * @see #getUserRestrictions() 258 */ 259 public static final String DISALLOW_FACTORY_RESET = "no_factory_reset"; 260 261 /** 262 * Specifies if a user is disallowed from adding new users and 263 * profiles. This can only be set by device owners and profile owners on the primary user. 264 * The default value is <code>false</code>. 265 * <p>This restriction has no effect on secondary users and managed profiles since only the 266 * primary user can add other users. 267 * 268 * <p>Key for user restrictions. 269 * <p>Type: Boolean 270 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 271 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 272 * @see #getUserRestrictions() 273 */ 274 public static final String DISALLOW_ADD_USER = "no_add_user"; 275 276 /** 277 * Specifies if a user is disallowed from disabling application 278 * verification. The default value is <code>false</code>. 279 * 280 * <p>Key for user restrictions. 281 * <p>Type: Boolean 282 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 283 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 284 * @see #getUserRestrictions() 285 */ 286 public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps"; 287 288 /** 289 * Specifies if a user is disallowed from configuring cell 290 * broadcasts. This can only be set by device owners and profile owners on the primary user. 291 * The default value is <code>false</code>. 292 * <p>This restriction has no effect on secondary users and managed profiles since only the 293 * primary user can configure cell broadcasts. 294 * 295 * <p>Key for user restrictions. 296 * <p>Type: Boolean 297 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 298 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 299 * @see #getUserRestrictions() 300 */ 301 public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts"; 302 303 /** 304 * Specifies if a user is disallowed from configuring mobile 305 * networks. This can only be set by device owners and profile owners on the primary user. 306 * The default value is <code>false</code>. 307 * <p>This restriction has no effect on secondary users and managed profiles since only the 308 * primary user can configure mobile networks. 309 * 310 * <p>Key for user restrictions. 311 * <p>Type: Boolean 312 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 313 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 314 * @see #getUserRestrictions() 315 */ 316 public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks"; 317 318 /** 319 * Specifies if a user is disallowed from modifying 320 * applications in Settings or launchers. The following actions will not be allowed when this 321 * restriction is enabled: 322 * <li>uninstalling apps</li> 323 * <li>disabling apps</li> 324 * <li>clearing app caches</li> 325 * <li>clearing app data</li> 326 * <li>force stopping apps</li> 327 * <li>clearing app defaults</li> 328 * <p> 329 * The default value is <code>false</code>. 330 * 331 * <p>Key for user restrictions. 332 * <p>Type: Boolean 333 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 334 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 335 * @see #getUserRestrictions() 336 */ 337 public static final String DISALLOW_APPS_CONTROL = "no_control_apps"; 338 339 /** 340 * Specifies if a user is disallowed from mounting 341 * physical external media. This can only be set by device owners and profile owners on the 342 * primary user. The default value is <code>false</code>. 343 * 344 * <p>Key for user restrictions. 345 * <p>Type: Boolean 346 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 347 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 348 * @see #getUserRestrictions() 349 */ 350 public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media"; 351 352 /** 353 * Specifies if a user is disallowed from adjusting microphone 354 * volume. If set, the microphone will be muted. This can only be set by device owners 355 * and profile owners on the primary user. The default value is <code>false</code>. 356 * 357 * <p>Key for user restrictions. 358 * <p>Type: Boolean 359 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 360 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 361 * @see #getUserRestrictions() 362 */ 363 public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone"; 364 365 /** 366 * Specifies if a user is disallowed from adjusting the master 367 * volume. If set, the master volume will be muted. This can only be set by device owners 368 * and profile owners on the primary user. The default value is <code>false</code>. 369 * 370 * <p>Key for user restrictions. 371 * <p>Type: Boolean 372 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 373 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 374 * @see #getUserRestrictions() 375 */ 376 public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume"; 377 378 /** 379 * Specifies that the user is not allowed to make outgoing 380 * phone calls. Emergency calls are still permitted. 381 * The default value is <code>false</code>. 382 * <p>This restriction has no effect on managed profiles. 383 * 384 * <p>Key for user restrictions. 385 * <p>Type: Boolean 386 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 387 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 388 * @see #getUserRestrictions() 389 */ 390 public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls"; 391 392 /** 393 * Specifies that the user is not allowed to send or receive 394 * SMS messages. The default value is <code>false</code>. 395 * 396 * <p>Key for user restrictions. 397 * <p>Type: Boolean 398 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 399 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 400 * @see #getUserRestrictions() 401 */ 402 public static final String DISALLOW_SMS = "no_sms"; 403 404 /** 405 * Specifies if the user is not allowed to have fun. In some cases, the 406 * device owner may wish to prevent the user from experiencing amusement or 407 * joy while using the device. The default value is <code>false</code>. 408 * 409 * <p>Key for user restrictions. 410 * <p>Type: Boolean 411 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 412 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 413 * @see #getUserRestrictions() 414 */ 415 public static final String DISALLOW_FUN = "no_fun"; 416 417 /** 418 * Specifies that windows besides app windows should not be 419 * created. This will block the creation of the following types of windows. 420 * <li>{@link LayoutParams#TYPE_TOAST}</li> 421 * <li>{@link LayoutParams#TYPE_PHONE}</li> 422 * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li> 423 * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li> 424 * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li> 425 * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li> 426 * 427 * <p>This can only be set by device owners and profile owners on the primary user. 428 * The default value is <code>false</code>. 429 * 430 * <p>Key for user restrictions. 431 * <p>Type: Boolean 432 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 433 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 434 * @see #getUserRestrictions() 435 */ 436 public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows"; 437 438 /** 439 * Specifies if what is copied in the clipboard of this profile can 440 * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be 441 * pasted in this profile. 442 * The default value is <code>false</code>. 443 * 444 * <p>Key for user restrictions. 445 * <p>Type: Boolean 446 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 447 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 448 * @see #getUserRestrictions() 449 */ 450 public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste"; 451 452 /** 453 * Specifies if the user is not allowed to use NFC to beam out data from apps. 454 * The default value is <code>false</code>. 455 * 456 * <p>Key for user restrictions. 457 * <p>Type: Boolean 458 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 459 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 460 * @see #getUserRestrictions() 461 */ 462 public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam"; 463 464 /** 465 * Hidden user restriction to disallow access to wallpaper manager APIs. This restriction 466 * generally means that wallpapers are not supported for the particular user. This user 467 * restriction is always set for managed profiles, because such profiles don't have wallpapers. 468 * @hide 469 * @see #DISALLOW_SET_WALLPAPER 470 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 471 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 472 * @see #getUserRestrictions() 473 */ 474 public static final String DISALLOW_WALLPAPER = "no_wallpaper"; 475 476 /** 477 * User restriction to disallow setting a wallpaper. Profile owner and device owner 478 * are able to set wallpaper regardless of this restriction. 479 * The default value is <code>false</code>. 480 * 481 * <p>Key for user restrictions. 482 * <p>Type: Boolean 483 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 484 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 485 * @see #getUserRestrictions() 486 */ 487 public static final String DISALLOW_SET_WALLPAPER = "no_set_wallpaper"; 488 489 /** 490 * Specifies if the user is not allowed to reboot the device into safe boot mode. 491 * This can only be set by device owners and profile owners on the primary user. 492 * The default value is <code>false</code>. 493 * 494 * <p>Key for user restrictions. 495 * <p>Type: Boolean 496 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 497 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 498 * @see #getUserRestrictions() 499 */ 500 public static final String DISALLOW_SAFE_BOOT = "no_safe_boot"; 501 502 /** 503 * Specifies if a user is not allowed to record audio. This restriction is always enabled for 504 * background users. The default value is <code>false</code>. 505 * 506 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 507 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 508 * @see #getUserRestrictions() 509 * @hide 510 */ 511 public static final String DISALLOW_RECORD_AUDIO = "no_record_audio"; 512 513 /** 514 * Specifies if a user is not allowed to run in the background and should be stopped during 515 * user switch. The default value is <code>false</code>. 516 * 517 * <p>This restriction can be set by device owners and profile owners. 518 * 519 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 520 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 521 * @see #getUserRestrictions() 522 * @hide 523 */ 524 public static final String DISALLOW_RUN_IN_BACKGROUND = "no_run_in_background"; 525 526 /** 527 * Specifies if a user is not allowed to use the camera. 528 * 529 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 530 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 531 * @see #getUserRestrictions() 532 * @hide 533 */ 534 public static final String DISALLOW_CAMERA = "no_camera"; 535 536 /** 537 * Specifies if a user is not allowed to use cellular data when roaming. This can only be set by 538 * device owners. The default value is <code>false</code>. 539 * 540 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 541 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 542 * @see #getUserRestrictions() 543 */ 544 public static final String DISALLOW_DATA_ROAMING = "no_data_roaming"; 545 546 /** 547 * Specifies if a user is not allowed to change their icon. Device owner and profile owner 548 * can set this restriction. When it is set by device owner, only the target user will be 549 * affected. The default value is <code>false</code>. 550 * 551 * <p>Key for user restrictions. 552 * <p>Type: Boolean 553 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 554 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 555 * @see #getUserRestrictions() 556 */ 557 public static final String DISALLOW_SET_USER_ICON = "no_set_user_icon"; 558 559 /** 560 * Allows apps in the parent profile to handle web links from the managed profile. 561 * 562 * This user restriction has an effect only in a managed profile. 563 * If set: 564 * Intent filters of activities in the parent profile with action 565 * {@link android.content.Intent#ACTION_VIEW}, 566 * category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which 567 * define a host can handle intents from the managed profile. 568 * The default value is <code>false</code>. 569 * 570 * <p>Key for user restrictions. 571 * <p>Type: Boolean 572 * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 573 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 574 * @see #getUserRestrictions() 575 */ 576 public static final String ALLOW_PARENT_PROFILE_APP_LINKING 577 = "allow_parent_profile_app_linking"; 578 579 /** 580 * Application restriction key that is used to indicate the pending arrival 581 * of real restrictions for the app. 582 * 583 * <p> 584 * Applications that support restrictions should check for the presence of this key. 585 * A <code>true</code> value indicates that restrictions may be applied in the near 586 * future but are not available yet. It is the responsibility of any 587 * management application that sets this flag to update it when the final 588 * restrictions are enforced. 589 * 590 * <p>Key for application restrictions. 591 * <p>Type: Boolean 592 * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions( 593 * android.content.ComponentName, String, Bundle) 594 * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions( 595 * android.content.ComponentName, String) 596 */ 597 public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending"; 598 599 private static final String ACTION_CREATE_USER = "android.os.action.CREATE_USER"; 600 601 /** 602 * Extra containing a name for the user being created. Optional parameter passed to 603 * ACTION_CREATE_USER activity. 604 * @hide 605 */ 606 public static final String EXTRA_USER_NAME = "android.os.extra.USER_NAME"; 607 608 /** 609 * Extra containing account name for the user being created. Optional parameter passed to 610 * ACTION_CREATE_USER activity. 611 * @hide 612 */ 613 public static final String EXTRA_USER_ACCOUNT_NAME = "android.os.extra.USER_ACCOUNT_NAME"; 614 615 /** 616 * Extra containing account type for the user being created. Optional parameter passed to 617 * ACTION_CREATE_USER activity. 618 * @hide 619 */ 620 public static final String EXTRA_USER_ACCOUNT_TYPE = "android.os.extra.USER_ACCOUNT_TYPE"; 621 622 /** 623 * Extra containing account-specific data for the user being created. Optional parameter passed 624 * to ACTION_CREATE_USER activity. 625 * @hide 626 */ 627 public static final String EXTRA_USER_ACCOUNT_OPTIONS 628 = "android.os.extra.USER_ACCOUNT_OPTIONS"; 629 630 /** @hide */ 631 public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3; 632 /** @hide */ 633 public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2; 634 /** @hide */ 635 public static final int PIN_VERIFICATION_SUCCESS = -1; 636 637 /** 638 * Error result indicating that this user is not allowed to add other users on this device. 639 * This is a result code returned from the activity created by the intent 640 * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}. 641 */ 642 public static final int USER_CREATION_FAILED_NOT_PERMITTED = Activity.RESULT_FIRST_USER; 643 644 /** 645 * Error result indicating that no more users can be created on this device. 646 * This is a result code returned from the activity created by the intent 647 * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}. 648 */ 649 public static final int USER_CREATION_FAILED_NO_MORE_USERS = Activity.RESULT_FIRST_USER + 1; 650 651 /** @hide */ 652 public static UserManager get(Context context) { 653 return (UserManager) context.getSystemService(Context.USER_SERVICE); 654 } 655 656 /** @hide */ 657 public UserManager(Context context, IUserManager service) { 658 mService = service; 659 mContext = context; 660 } 661 662 /** 663 * Returns whether the system supports multiple users. 664 * @return true if multiple users can be created by user, false if it is a single user device. 665 * @hide 666 */ 667 public static boolean supportsMultipleUsers() { 668 return getMaxSupportedUsers() > 1 669 && SystemProperties.getBoolean("fw.show_multiuserui", 670 Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI)); 671 } 672 673 /** 674 * @hide 675 * @return Whether the device is running with split system user. It means the system user and 676 * primary user are two separate users. Previously system user and primary user are combined as 677 * a single owner user. see @link {android.os.UserHandle#USER_OWNER} 678 */ 679 public static boolean isSplitSystemUser() { 680 return SystemProperties.getBoolean("ro.fw.system_user_split", false); 681 } 682 683 /** 684 * Returns whether switching users is currently allowed. 685 * <p>For instance switching users is not allowed if the current user is in a phone call, 686 * or system user hasn't been unlocked yet 687 * @hide 688 */ 689 public boolean canSwitchUsers() { 690 boolean allowUserSwitchingWhenSystemUserLocked = Settings.Global.getInt( 691 mContext.getContentResolver(), 692 Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0; 693 boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM); 694 boolean inCall = TelephonyManager.getDefault().getCallState() 695 != TelephonyManager.CALL_STATE_IDLE; 696 return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall; 697 } 698 699 /** 700 * Returns the user handle for the user that this process is running under. 701 * 702 * @return the user handle of this process. 703 * @hide 704 */ 705 public @UserIdInt int getUserHandle() { 706 return UserHandle.myUserId(); 707 } 708 709 /** 710 * Returns the user name of the user making this call. This call is only 711 * available to applications on the system image; it requires the 712 * MANAGE_USERS permission. 713 * @return the user name 714 */ 715 public String getUserName() { 716 try { 717 return mService.getUserInfo(getUserHandle()).name; 718 } catch (RemoteException re) { 719 throw re.rethrowFromSystemServer(); 720 } 721 } 722 723 /** 724 * Used to determine whether the user making this call is subject to 725 * teleportations. 726 * 727 * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can 728 * now automatically identify goats using advanced goat recognition technology.</p> 729 * 730 * @return Returns true if the user making this call is a goat. 731 */ 732 public boolean isUserAGoat() { 733 return mContext.getPackageManager() 734 .isPackageAvailable("com.coffeestainstudios.goatsimulator"); 735 } 736 737 /** 738 * Used to check if this process is running under the primary user. The primary user 739 * is the first human user on a device. 740 * 741 * @return whether this process is running under the primary user. 742 * @hide 743 */ 744 public boolean isPrimaryUser() { 745 UserInfo user = getUserInfo(UserHandle.myUserId()); 746 return user != null ? user.isPrimary() : false; 747 } 748 749 /** 750 * Used to check if this process is running under the system user. The system user 751 * is the initial user that is implicitly created on first boot and hosts most of the 752 * system services. 753 * 754 * @return whether this process is running under the system user. 755 */ 756 public boolean isSystemUser() { 757 return UserHandle.myUserId() == UserHandle.USER_SYSTEM; 758 } 759 760 /** 761 * @hide 762 * Returns whether the caller is running as an admin user. There can be more than one admin 763 * user. 764 */ 765 public boolean isAdminUser() { 766 return isUserAdmin(UserHandle.myUserId()); 767 } 768 769 /** 770 * @hide 771 * Returns whether the provided user is an admin user. There can be more than one admin 772 * user. 773 */ 774 public boolean isUserAdmin(@UserIdInt int userId) { 775 UserInfo user = getUserInfo(userId); 776 return user != null && user.isAdmin(); 777 } 778 779 /** 780 * Used to check if the user making this call is linked to another user. Linked users may have 781 * a reduced number of available apps, app restrictions and account restrictions. 782 * @return whether the user making this call is a linked user 783 * @hide 784 */ 785 public boolean isLinkedUser() { 786 try { 787 return mService.isRestricted(); 788 } catch (RemoteException re) { 789 throw re.rethrowFromSystemServer(); 790 } 791 } 792 793 /** 794 * Checks if specified user can have restricted profile. 795 * @hide 796 */ 797 public boolean canHaveRestrictedProfile(@UserIdInt int userId) { 798 try { 799 return mService.canHaveRestrictedProfile(userId); 800 } catch (RemoteException re) { 801 throw re.rethrowFromSystemServer(); 802 } 803 } 804 805 /** 806 * Checks if the calling app is running as a guest user. 807 * @return whether the caller is a guest user. 808 * @hide 809 */ 810 public boolean isGuestUser() { 811 UserInfo user = getUserInfo(UserHandle.myUserId()); 812 return user != null ? user.isGuest() : false; 813 } 814 815 /** 816 * Checks if the calling app is running in a managed profile. 817 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 818 * 819 * @return whether the caller is in a managed profile. 820 * @hide 821 */ 822 @SystemApi 823 public boolean isManagedProfile() { 824 UserInfo user = getUserInfo(UserHandle.myUserId()); 825 return user != null ? user.isManagedProfile() : false; 826 } 827 828 /** 829 * Checks if the calling app is running as an ephemeral user. 830 * 831 * @return whether the caller is an ephemeral user. 832 * @hide 833 */ 834 public boolean isEphemeralUser() { 835 return isUserEphemeral(UserHandle.myUserId()); 836 } 837 838 /** 839 * Returns whether the specified user is ephemeral. 840 * @hide 841 */ 842 public boolean isUserEphemeral(@UserIdInt int userId) { 843 final UserInfo user = getUserInfo(userId); 844 return user != null && user.isEphemeral(); 845 } 846 847 /** 848 * Return whether the given user is actively running. This means that 849 * the user is in the "started" state, not "stopped" -- it is currently 850 * allowed to run code through scheduled alarms, receiving broadcasts, 851 * etc. A started user may be either the current foreground user or a 852 * background user; the result here does not distinguish between the two. 853 * @param user The user to retrieve the running state for. 854 */ 855 public boolean isUserRunning(UserHandle user) { 856 return isUserRunning(user.getIdentifier()); 857 } 858 859 /** {@hide} */ 860 public boolean isUserRunning(int userId) { 861 try { 862 return ActivityManagerNative.getDefault().isUserRunning(userId, 0); 863 } catch (RemoteException re) { 864 throw re.rethrowFromSystemServer(); 865 } 866 } 867 868 /** 869 * Return whether the given user is actively running <em>or</em> stopping. 870 * This is like {@link #isUserRunning(UserHandle)}, but will also return 871 * true if the user had been running but is in the process of being stopped 872 * (but is not yet fully stopped, and still running some code). 873 * @param user The user to retrieve the running state for. 874 */ 875 public boolean isUserRunningOrStopping(UserHandle user) { 876 try { 877 // TODO: reconcile stopped vs stopping? 878 return ActivityManagerNative.getDefault().isUserRunning( 879 user.getIdentifier(), ActivityManager.FLAG_OR_STOPPED); 880 } catch (RemoteException re) { 881 throw re.rethrowFromSystemServer(); 882 } 883 } 884 885 /** 886 * Return whether the calling user is running in a "locked" state. A user is 887 * unlocked only after they've entered their credentials (such as a lock 888 * pattern or PIN), and credential-encrypted private app data storage is 889 * available. 890 */ 891 @Deprecated 892 public boolean isUserRunningAndLocked() { 893 return isUserRunningAndLocked(Process.myUserHandle()); 894 } 895 896 /** 897 * Return whether the given user is running in a "locked" state. A user 898 * is unlocked only after they've entered their credentials (such as a lock 899 * pattern or PIN), and credential-encrypted private app data storage is 900 * available. 901 * 902 * @param user to retrieve the unlocked state for. 903 */ 904 @Deprecated 905 public boolean isUserRunningAndLocked(UserHandle user) { 906 try { 907 return ActivityManagerNative.getDefault().isUserRunning( 908 user.getIdentifier(), ActivityManager.FLAG_AND_LOCKED); 909 } catch (RemoteException re) { 910 throw re.rethrowFromSystemServer(); 911 } 912 } 913 914 /** 915 * Return whether the calling user is running in an "unlocked" state. A user 916 * is unlocked only after they've entered their credentials (such as a lock 917 * pattern or PIN), and credential-encrypted private app data storage is 918 * available. 919 */ 920 @Deprecated 921 public boolean isUserRunningAndUnlocked() { 922 return isUserRunningAndUnlocked(Process.myUserHandle()); 923 } 924 925 /** 926 * Return whether the given user is running in an "unlocked" state. A user 927 * is unlocked only after they've entered their credentials (such as a lock 928 * pattern or PIN), and credential-encrypted private app data storage is 929 * available. 930 * 931 * @param user to retrieve the unlocked state for. 932 */ 933 @Deprecated 934 public boolean isUserRunningAndUnlocked(UserHandle user) { 935 try { 936 return ActivityManagerNative.getDefault().isUserRunning( 937 user.getIdentifier(), ActivityManager.FLAG_AND_UNLOCKED); 938 } catch (RemoteException re) { 939 throw re.rethrowFromSystemServer(); 940 } 941 } 942 943 /** 944 * Return whether the calling user is running in an "unlocked" state. A user 945 * is unlocked only after they've entered their credentials (such as a lock 946 * pattern or PIN), and credential-encrypted private app data storage is 947 * available. 948 */ 949 public boolean isUserUnlocked() { 950 return isUserUnlocked(Process.myUserHandle()); 951 } 952 953 /** 954 * Return whether the given user is running in an "unlocked" state. A user 955 * is unlocked only after they've entered their credentials (such as a lock 956 * pattern or PIN), and credential-encrypted private app data storage is 957 * available. 958 * 959 * @param user to retrieve the unlocked state for. 960 */ 961 public boolean isUserUnlocked(UserHandle user) { 962 return isUserUnlocked(user.getIdentifier()); 963 } 964 965 /** {@hide} */ 966 public boolean isUserUnlocked(@UserIdInt int userId) { 967 // TODO: eventually pivot this back to look at ActivityManager state, 968 // but there is race where we can start a non-encryption-aware launcher 969 // before that lifecycle has entered the running unlocked state. 970 return mContext.getSystemService(StorageManager.class).isUserKeyUnlocked(userId); 971 } 972 973 /** 974 * Returns the UserInfo object describing a specific user. 975 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission or the caller is 976 * in the same profile group of target user. 977 * @param userHandle the user handle of the user whose information is being requested. 978 * @return the UserInfo object for a specific user. 979 * @hide 980 */ 981 public UserInfo getUserInfo(@UserIdInt int userHandle) { 982 try { 983 return mService.getUserInfo(userHandle); 984 } catch (RemoteException re) { 985 throw re.rethrowFromSystemServer(); 986 } 987 } 988 989 /** 990 * Returns the user-wide restrictions imposed on this user. 991 * @return a Bundle containing all the restrictions. 992 */ 993 public Bundle getUserRestrictions() { 994 return getUserRestrictions(Process.myUserHandle()); 995 } 996 997 /** 998 * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>. 999 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 1000 * @return a Bundle containing all the restrictions. 1001 */ 1002 public Bundle getUserRestrictions(UserHandle userHandle) { 1003 try { 1004 return mService.getUserRestrictions(userHandle.getIdentifier()); 1005 } catch (RemoteException re) { 1006 throw re.rethrowFromSystemServer(); 1007 } 1008 } 1009 1010 /** 1011 * @hide 1012 * Returns whether the given user has been disallowed from performing certain actions 1013 * or setting certain settings through UserManager. This method disregards restrictions 1014 * set by device policy. 1015 * @param restrictionKey the string key representing the restriction 1016 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 1017 */ 1018 public boolean hasBaseUserRestriction(String restrictionKey, UserHandle userHandle) { 1019 try { 1020 return mService.hasBaseUserRestriction(restrictionKey, userHandle.getIdentifier()); 1021 } catch (RemoteException re) { 1022 throw re.rethrowFromSystemServer(); 1023 } 1024 } 1025 1026 /** 1027 * This will no longer work. Device owners and profile owners should use 1028 * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead. 1029 */ 1030 // System apps should use UserManager.setUserRestriction() instead. 1031 @Deprecated 1032 public void setUserRestrictions(Bundle restrictions) { 1033 throw new UnsupportedOperationException("This method is no longer supported"); 1034 } 1035 1036 /** 1037 * This will no longer work. Device owners and profile owners should use 1038 * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead. 1039 */ 1040 // System apps should use UserManager.setUserRestriction() instead. 1041 @Deprecated 1042 public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) { 1043 throw new UnsupportedOperationException("This method is no longer supported"); 1044 } 1045 1046 /** 1047 * Sets the value of a specific restriction. 1048 * Requires the MANAGE_USERS permission. 1049 * @param key the key of the restriction 1050 * @param value the value for the restriction 1051 * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction( 1052 * android.content.ComponentName, String)} or 1053 * {@link android.app.admin.DevicePolicyManager#clearUserRestriction( 1054 * android.content.ComponentName, String)} instead. 1055 */ 1056 @Deprecated 1057 public void setUserRestriction(String key, boolean value) { 1058 setUserRestriction(key, value, Process.myUserHandle()); 1059 } 1060 1061 /** 1062 * @hide 1063 * Sets the value of a specific restriction on a specific user. 1064 * Requires the MANAGE_USERS permission. 1065 * @param key the key of the restriction 1066 * @param value the value for the restriction 1067 * @param userHandle the user whose restriction is to be changed. 1068 * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction( 1069 * android.content.ComponentName, String)} or 1070 * {@link android.app.admin.DevicePolicyManager#clearUserRestriction( 1071 * android.content.ComponentName, String)} instead. 1072 */ 1073 @Deprecated 1074 public void setUserRestriction(String key, boolean value, UserHandle userHandle) { 1075 try { 1076 mService.setUserRestriction(key, value, userHandle.getIdentifier()); 1077 } catch (RemoteException re) { 1078 throw re.rethrowFromSystemServer(); 1079 } 1080 } 1081 1082 /** 1083 * Returns whether the current user has been disallowed from performing certain actions 1084 * or setting certain settings. 1085 * 1086 * @param restrictionKey The string key representing the restriction. 1087 * @return {@code true} if the current user has the given restriction, {@code false} otherwise. 1088 */ 1089 public boolean hasUserRestriction(String restrictionKey) { 1090 return hasUserRestriction(restrictionKey, Process.myUserHandle()); 1091 } 1092 1093 /** 1094 * @hide 1095 * Returns whether the given user has been disallowed from performing certain actions 1096 * or setting certain settings. 1097 * @param restrictionKey the string key representing the restriction 1098 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 1099 */ 1100 public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) { 1101 try { 1102 return mService.hasUserRestriction(restrictionKey, 1103 userHandle.getIdentifier()); 1104 } catch (RemoteException re) { 1105 throw re.rethrowFromSystemServer(); 1106 } 1107 } 1108 1109 /** 1110 * Return the serial number for a user. This is a device-unique 1111 * number assigned to that user; if the user is deleted and then a new 1112 * user created, the new users will not be given the same serial number. 1113 * @param user The user whose serial number is to be retrieved. 1114 * @return The serial number of the given user; returns -1 if the 1115 * given UserHandle does not exist. 1116 * @see #getUserForSerialNumber(long) 1117 */ 1118 public long getSerialNumberForUser(UserHandle user) { 1119 return getUserSerialNumber(user.getIdentifier()); 1120 } 1121 1122 /** 1123 * Return the user associated with a serial number previously 1124 * returned by {@link #getSerialNumberForUser(UserHandle)}. 1125 * @param serialNumber The serial number of the user that is being 1126 * retrieved. 1127 * @return Return the user associated with the serial number, or null 1128 * if there is not one. 1129 * @see #getSerialNumberForUser(UserHandle) 1130 */ 1131 public UserHandle getUserForSerialNumber(long serialNumber) { 1132 int ident = getUserHandle((int) serialNumber); 1133 return ident >= 0 ? new UserHandle(ident) : null; 1134 } 1135 1136 /** 1137 * Creates a user with the specified name and options. For non-admin users, default user 1138 * restrictions are going to be applied. 1139 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1140 * 1141 * @param name the user's name 1142 * @param flags flags that identify the type of user and other properties. 1143 * @see UserInfo 1144 * 1145 * @return the UserInfo object for the created user, or null if the user could not be created. 1146 * @hide 1147 */ 1148 public UserInfo createUser(String name, int flags) { 1149 UserInfo user = null; 1150 try { 1151 user = mService.createUser(name, flags); 1152 // TODO: Keep this in sync with 1153 // UserManagerService.LocalService.createUserEvenWhenDisallowed 1154 if (user != null && !user.isAdmin()) { 1155 mService.setUserRestriction(DISALLOW_SMS, true, user.id); 1156 mService.setUserRestriction(DISALLOW_OUTGOING_CALLS, true, user.id); 1157 } 1158 } catch (RemoteException re) { 1159 throw re.rethrowFromSystemServer(); 1160 } 1161 return user; 1162 } 1163 1164 /** 1165 * Creates a guest user and configures it. 1166 * @param context an application context 1167 * @param name the name to set for the user 1168 * @hide 1169 */ 1170 public UserInfo createGuest(Context context, String name) { 1171 UserInfo guest = null; 1172 try { 1173 guest = mService.createUser(name, UserInfo.FLAG_GUEST); 1174 if (guest != null) { 1175 Settings.Secure.putStringForUser(context.getContentResolver(), 1176 Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id); 1177 } 1178 } catch (RemoteException re) { 1179 throw re.rethrowFromSystemServer(); 1180 } 1181 return guest; 1182 } 1183 1184 /** 1185 * Creates a user with the specified name and options as a profile of another user. 1186 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1187 * 1188 * @param name the user's name 1189 * @param flags flags that identify the type of user and other properties. 1190 * @see UserInfo 1191 * @param userHandle new user will be a profile of this use. 1192 * 1193 * @return the UserInfo object for the created user, or null if the user could not be created. 1194 * @hide 1195 */ 1196 public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle) { 1197 try { 1198 return mService.createProfileForUser(name, flags, userHandle); 1199 } catch (RemoteException re) { 1200 throw re.rethrowFromSystemServer(); 1201 } 1202 } 1203 1204 /** 1205 * Creates a restricted profile with the specified name. This method also sets necessary 1206 * restrictions and adds shared accounts. 1207 * 1208 * @param name profile's name 1209 * @return UserInfo object for the created user, or null if the user could not be created. 1210 * @hide 1211 */ 1212 public UserInfo createRestrictedProfile(String name) { 1213 try { 1214 UserHandle parentUserHandle = Process.myUserHandle(); 1215 UserInfo user = mService.createRestrictedProfile(name, 1216 parentUserHandle.getIdentifier()); 1217 if (user != null) { 1218 AccountManager.get(mContext).addSharedAccountsFromParentUser(parentUserHandle, 1219 UserHandle.of(user.id)); 1220 } 1221 return user; 1222 } catch (RemoteException re) { 1223 throw re.rethrowFromSystemServer(); 1224 } 1225 } 1226 1227 /** 1228 * Returns an intent to create a user for the provided name and email address. The name 1229 * and email address will be used when the setup process for the new user is started. 1230 * If this device does not support multiple users, null is returned. 1231 * <p/> 1232 * The intent should be launched using startActivityForResult and the return result will 1233 * indicate if the user consented to adding a new user and if the operation succeeded. Any 1234 * errors in creating the user will be returned in the result code. If the user cancels the 1235 * request, the return result will be {@link Activity#RESULT_CANCELED}. On success, the 1236 * result code will be {@link Activity#RESULT_OK}. 1237 * <p/> 1238 * The new user is created but not initialized. After switching into the user for the first 1239 * time, the preferred user name and account information are used by the setup process for that 1240 * user. 1241 * 1242 * @param userName Optional name to assign to the user. 1243 * @param accountName Optional email address that will be used by the setup wizard to initialize 1244 * the user. 1245 * @param accountType Optional account type for the account to be created. This is required 1246 * if the account name is specified. 1247 * @param accountOptions Optional bundle of data to be passed in during account creation in the 1248 * new user via {@link AccountManager#addAccount(String, String, String[], 1249 * Bundle, android.app.Activity, android.accounts.AccountManagerCallback, 1250 * Handler)}. 1251 * @return An Intent that can be launched from an Activity or null if creating users is not 1252 * supported on this device. 1253 * @see #USER_CREATION_FAILED_NOT_PERMITTED 1254 * @see #USER_CREATION_FAILED_NO_MORE_USERS 1255 */ 1256 public static Intent createUserCreationIntent(@Nullable String userName, 1257 @Nullable String accountName, 1258 @Nullable String accountType, @Nullable PersistableBundle accountOptions) { 1259 if (!supportsMultipleUsers() || getMaxSupportedUsers() < 2) { 1260 return null; 1261 } 1262 Intent intent = new Intent(ACTION_CREATE_USER); 1263 if (userName != null) { 1264 intent.putExtra(EXTRA_USER_NAME, userName); 1265 } 1266 if (accountName != null && accountType == null) { 1267 throw new IllegalArgumentException("accountType must be specified if accountName is " 1268 + "specified"); 1269 } 1270 if (accountName != null) { 1271 intent.putExtra(EXTRA_USER_ACCOUNT_NAME, accountName); 1272 } 1273 if (accountType != null) { 1274 intent.putExtra(EXTRA_USER_ACCOUNT_TYPE, accountType); 1275 } 1276 if (accountOptions != null) { 1277 intent.putExtra(EXTRA_USER_ACCOUNT_OPTIONS, accountOptions); 1278 } 1279 return intent; 1280 } 1281 1282 /** 1283 * @hide 1284 * 1285 * Returns the preferred account name for user creation. Requires MANAGE_USERS permission. 1286 */ 1287 @SystemApi 1288 public String getSeedAccountName() { 1289 try { 1290 return mService.getSeedAccountName(); 1291 } catch (RemoteException re) { 1292 throw re.rethrowFromSystemServer(); 1293 } 1294 } 1295 1296 /** 1297 * @hide 1298 * 1299 * Returns the preferred account type for user creation. Requires MANAGE_USERS permission. 1300 */ 1301 @SystemApi 1302 public String getSeedAccountType() { 1303 try { 1304 return mService.getSeedAccountType(); 1305 } catch (RemoteException re) { 1306 throw re.rethrowFromSystemServer(); 1307 } 1308 } 1309 1310 /** 1311 * @hide 1312 * 1313 * Returns the preferred account's options bundle for user creation. Requires MANAGE_USERS 1314 * permission. 1315 * @return Any options set by the requestor that created the user. 1316 */ 1317 @SystemApi 1318 public PersistableBundle getSeedAccountOptions() { 1319 try { 1320 return mService.getSeedAccountOptions(); 1321 } catch (RemoteException re) { 1322 throw re.rethrowFromSystemServer(); 1323 } 1324 } 1325 1326 /** 1327 * @hide 1328 * 1329 * Called by a system activity to set the seed account information of a user created 1330 * through the user creation intent. 1331 * @param userId 1332 * @param accountName 1333 * @param accountType 1334 * @param accountOptions 1335 * @see #createUserCreationIntent(String, String, String, PersistableBundle) 1336 */ 1337 public void setSeedAccountData(int userId, String accountName, String accountType, 1338 PersistableBundle accountOptions) { 1339 try { 1340 mService.setSeedAccountData(userId, accountName, accountType, accountOptions, 1341 /* persist= */ true); 1342 } catch (RemoteException re) { 1343 throw re.rethrowFromSystemServer(); 1344 } 1345 } 1346 1347 /** 1348 * @hide 1349 * Clears the seed information used to create this user. Requires MANAGE_USERS permission. 1350 */ 1351 @SystemApi 1352 public void clearSeedAccountData() { 1353 try { 1354 mService.clearSeedAccountData(); 1355 } catch (RemoteException re) { 1356 throw re.rethrowFromSystemServer(); 1357 } 1358 } 1359 1360 /** 1361 * @hide 1362 * Marks the guest user for deletion to allow a new guest to be created before deleting 1363 * the current user who is a guest. 1364 * @param userHandle 1365 * @return 1366 */ 1367 public boolean markGuestForDeletion(@UserIdInt int userHandle) { 1368 try { 1369 return mService.markGuestForDeletion(userHandle); 1370 } catch (RemoteException re) { 1371 throw re.rethrowFromSystemServer(); 1372 } 1373 } 1374 1375 /** 1376 * Sets the user as enabled, if such an user exists. 1377 * 1378 * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1379 * 1380 * <p>Note that the default is true, it's only that managed profiles might not be enabled. 1381 * Also ephemeral users can be disabled to indicate that their removal is in progress and they 1382 * shouldn't be re-entered. Therefore ephemeral users should not be re-enabled once disabled. 1383 * 1384 * @param userHandle the id of the profile to enable 1385 * @hide 1386 */ 1387 public void setUserEnabled(@UserIdInt int userHandle) { 1388 try { 1389 mService.setUserEnabled(userHandle); 1390 } catch (RemoteException re) { 1391 throw re.rethrowFromSystemServer(); 1392 } 1393 } 1394 1395 /** 1396 * Return the number of users currently created on the device. 1397 */ 1398 public int getUserCount() { 1399 List<UserInfo> users = getUsers(); 1400 return users != null ? users.size() : 1; 1401 } 1402 1403 /** 1404 * Returns information for all users on this device. 1405 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1406 * @return the list of users that exist on the device. 1407 * @hide 1408 */ 1409 public List<UserInfo> getUsers() { 1410 try { 1411 return mService.getUsers(false); 1412 } catch (RemoteException re) { 1413 throw re.rethrowFromSystemServer(); 1414 } 1415 } 1416 1417 /** 1418 * Returns serial numbers of all users on this device. 1419 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1420 * 1421 * @param excludeDying specify if the list should exclude users being removed. 1422 * @return the list of serial numbers of users that exist on the device. 1423 * @hide 1424 */ 1425 @SystemApi 1426 public long[] getSerialNumbersOfUsers(boolean excludeDying) { 1427 try { 1428 List<UserInfo> users = mService.getUsers(excludeDying); 1429 long[] result = new long[users.size()]; 1430 for (int i = 0; i < result.length; i++) { 1431 result[i] = users.get(i).serialNumber; 1432 } 1433 return result; 1434 } catch (RemoteException re) { 1435 throw re.rethrowFromSystemServer(); 1436 } 1437 } 1438 1439 /** 1440 * @return the user's account name, null if not found. 1441 * @hide 1442 */ 1443 @RequiresPermission( allOf = { 1444 Manifest.permission.INTERACT_ACROSS_USERS_FULL, 1445 Manifest.permission.MANAGE_USERS 1446 }) 1447 public @Nullable String getUserAccount(@UserIdInt int userHandle) { 1448 try { 1449 return mService.getUserAccount(userHandle); 1450 } catch (RemoteException re) { 1451 throw re.rethrowFromSystemServer(); 1452 } 1453 } 1454 1455 /** 1456 * Set account name for the given user. 1457 * @hide 1458 */ 1459 @RequiresPermission( allOf = { 1460 Manifest.permission.INTERACT_ACROSS_USERS_FULL, 1461 Manifest.permission.MANAGE_USERS 1462 }) 1463 public void setUserAccount(@UserIdInt int userHandle, @Nullable String accountName) { 1464 try { 1465 mService.setUserAccount(userHandle, accountName); 1466 } catch (RemoteException re) { 1467 throw re.rethrowFromSystemServer(); 1468 } 1469 } 1470 1471 /** 1472 * Returns information for Primary user. 1473 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1474 * 1475 * @return the Primary user, null if not found. 1476 * @hide 1477 */ 1478 public @Nullable UserInfo getPrimaryUser() { 1479 try { 1480 return mService.getPrimaryUser(); 1481 } catch (RemoteException re) { 1482 throw re.rethrowFromSystemServer(); 1483 } 1484 } 1485 1486 /** 1487 * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS 1488 * permission. 1489 * 1490 * @return true if more users can be added, false if limit has been reached. 1491 * @hide 1492 */ 1493 public boolean canAddMoreUsers() { 1494 final List<UserInfo> users = getUsers(true); 1495 final int totalUserCount = users.size(); 1496 int aliveUserCount = 0; 1497 for (int i = 0; i < totalUserCount; i++) { 1498 UserInfo user = users.get(i); 1499 if (!user.isGuest()) { 1500 aliveUserCount++; 1501 } 1502 } 1503 return aliveUserCount < getMaxSupportedUsers(); 1504 } 1505 1506 /** 1507 * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS 1508 * permission. 1509 * if allowedToRemoveOne is true and if the user already has a managed profile, then return if 1510 * we could add a new managed profile to this user after removing the existing one. 1511 * 1512 * @return true if more managed profiles can be added, false if limit has been reached. 1513 * @hide 1514 */ 1515 public boolean canAddMoreManagedProfiles(@UserIdInt int userId, boolean allowedToRemoveOne) { 1516 try { 1517 return mService.canAddMoreManagedProfiles(userId, allowedToRemoveOne); 1518 } catch (RemoteException re) { 1519 throw re.rethrowFromSystemServer(); 1520 } 1521 } 1522 1523 /** 1524 * Returns list of the profiles of userHandle including 1525 * userHandle itself. 1526 * Note that this returns both enabled and not enabled profiles. See 1527 * {@link #getEnabledProfiles(int)} if you need only the enabled ones. 1528 * 1529 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1530 * @param userHandle profiles of this user will be returned. 1531 * @return the list of profiles. 1532 * @hide 1533 */ 1534 public List<UserInfo> getProfiles(@UserIdInt int userHandle) { 1535 try { 1536 return mService.getProfiles(userHandle, false /* enabledOnly */); 1537 } catch (RemoteException re) { 1538 throw re.rethrowFromSystemServer(); 1539 } 1540 } 1541 1542 /** 1543 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1544 * @param userId one of the two user ids to check. 1545 * @param otherUserId one of the two user ids to check. 1546 * @return true if the two user ids are in the same profile group. 1547 * @hide 1548 */ 1549 public boolean isSameProfileGroup(@UserIdInt int userId, int otherUserId) { 1550 try { 1551 return mService.isSameProfileGroup(userId, otherUserId); 1552 } catch (RemoteException re) { 1553 throw re.rethrowFromSystemServer(); 1554 } 1555 } 1556 1557 /** 1558 * Returns list of the profiles of userHandle including 1559 * userHandle itself. 1560 * Note that this returns only enabled. 1561 * 1562 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1563 * @param userHandle profiles of this user will be returned. 1564 * @return the list of profiles. 1565 * @hide 1566 */ 1567 public List<UserInfo> getEnabledProfiles(@UserIdInt int userHandle) { 1568 try { 1569 return mService.getProfiles(userHandle, true /* enabledOnly */); 1570 } catch (RemoteException re) { 1571 throw re.rethrowFromSystemServer(); 1572 } 1573 } 1574 1575 /** 1576 * Returns a list of UserHandles for profiles associated with the user that the calling process 1577 * is running on, including the user itself. 1578 * 1579 * @return A non-empty list of UserHandles associated with the calling user. 1580 */ 1581 public List<UserHandle> getUserProfiles() { 1582 ArrayList<UserHandle> profiles = new ArrayList<UserHandle>(); 1583 List<UserInfo> users; 1584 try { 1585 users = mService.getProfiles(UserHandle.myUserId(), true /* enabledOnly */); 1586 } catch (RemoteException re) { 1587 throw re.rethrowFromSystemServer(); 1588 } 1589 for (UserInfo info : users) { 1590 UserHandle userHandle = new UserHandle(info.id); 1591 profiles.add(userHandle); 1592 } 1593 return profiles; 1594 } 1595 1596 /** 1597 * Returns the device credential owner id of the profile from 1598 * which this method is called, or userHandle if called from a user that 1599 * is not a profile. 1600 * 1601 * @hide 1602 */ 1603 public int getCredentialOwnerProfile(@UserIdInt int userHandle) { 1604 try { 1605 return mService.getCredentialOwnerProfile(userHandle); 1606 } catch (RemoteException re) { 1607 throw re.rethrowFromSystemServer(); 1608 } 1609 } 1610 1611 /** 1612 * Returns the parent of the profile which this method is called from 1613 * or null if called from a user that is not a profile. 1614 * 1615 * @hide 1616 */ 1617 public UserInfo getProfileParent(@UserIdInt int userHandle) { 1618 try { 1619 return mService.getProfileParent(userHandle); 1620 } catch (RemoteException re) { 1621 throw re.rethrowFromSystemServer(); 1622 } 1623 } 1624 1625 /** 1626 * Set quiet mode of a managed profile. 1627 * 1628 * @param userHandle The user handle of the profile. 1629 * @param enableQuietMode Whether quiet mode should be enabled or disabled. 1630 * @hide 1631 */ 1632 public void setQuietModeEnabled(@UserIdInt int userHandle, boolean enableQuietMode) { 1633 try { 1634 mService.setQuietModeEnabled(userHandle, enableQuietMode); 1635 } catch (RemoteException re) { 1636 throw re.rethrowFromSystemServer(); 1637 } 1638 } 1639 1640 /** 1641 * Returns whether the given profile is in quiet mode or not. 1642 * 1643 * @param userHandle The user handle of the profile to be queried. 1644 * @return true if the profile is in quiet mode, false otherwise. 1645 */ 1646 public boolean isQuietModeEnabled(UserHandle userHandle) { 1647 try { 1648 return mService.isQuietModeEnabled(userHandle.getIdentifier()); 1649 } catch (RemoteException re) { 1650 throw re.rethrowFromSystemServer(); 1651 } 1652 } 1653 1654 /** 1655 * If the target user is a managed profile of the calling user or the caller 1656 * is itself a managed profile, then this returns a badged copy of the given 1657 * icon to be able to distinguish it from the original icon. For badging an 1658 * arbitrary drawable use {@link #getBadgedDrawableForUser( 1659 * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}. 1660 * <p> 1661 * If the original drawable is a BitmapDrawable and the backing bitmap is 1662 * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging 1663 * is performed in place and the original drawable is returned. 1664 * </p> 1665 * 1666 * @param icon The icon to badge. 1667 * @param user The target user. 1668 * @return A drawable that combines the original icon and a badge as 1669 * determined by the system. 1670 * @removed 1671 */ 1672 public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) { 1673 return mContext.getPackageManager().getUserBadgedIcon(icon, user); 1674 } 1675 1676 /** 1677 * If the target user is a managed profile of the calling user or the caller 1678 * is itself a managed profile, then this returns a badged copy of the given 1679 * drawable allowing the user to distinguish it from the original drawable. 1680 * The caller can specify the location in the bounds of the drawable to be 1681 * badged where the badge should be applied as well as the density of the 1682 * badge to be used. 1683 * <p> 1684 * If the original drawable is a BitmapDrawable and the backing bitmap is 1685 * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging 1686 * is performed in place and the original drawable is returned. 1687 * </p> 1688 * 1689 * @param badgedDrawable The drawable to badge. 1690 * @param user The target user. 1691 * @param badgeLocation Where in the bounds of the badged drawable to place 1692 * the badge. If it's {@code null}, the badge is applied on top of the entire 1693 * drawable being badged. 1694 * @param badgeDensity The optional desired density for the badge as per 1695 * {@link android.util.DisplayMetrics#densityDpi}. If it's not positive, 1696 * the density of the display is used. 1697 * @return A drawable that combines the original drawable and a badge as 1698 * determined by the system. 1699 * @removed 1700 */ 1701 public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user, 1702 Rect badgeLocation, int badgeDensity) { 1703 return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user, 1704 badgeLocation, badgeDensity); 1705 } 1706 1707 /** 1708 * If the target user is a managed profile of the calling user or the caller 1709 * is itself a managed profile, then this returns a copy of the label with 1710 * badging for accessibility services like talkback. E.g. passing in "Email" 1711 * and it might return "Work Email" for Email in the work profile. 1712 * 1713 * @param label The label to change. 1714 * @param user The target user. 1715 * @return A label that combines the original label and a badge as 1716 * determined by the system. 1717 * @removed 1718 */ 1719 public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) { 1720 return mContext.getPackageManager().getUserBadgedLabel(label, user); 1721 } 1722 1723 /** 1724 * Returns information for all users on this device. Requires 1725 * {@link android.Manifest.permission#MANAGE_USERS} permission. 1726 * 1727 * @param excludeDying specify if the list should exclude users being 1728 * removed. 1729 * @return the list of users that were created. 1730 * @hide 1731 */ 1732 public List<UserInfo> getUsers(boolean excludeDying) { 1733 try { 1734 return mService.getUsers(excludeDying); 1735 } catch (RemoteException re) { 1736 throw re.rethrowFromSystemServer(); 1737 } 1738 } 1739 1740 /** 1741 * Removes a user and all associated data. 1742 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1743 * @param userHandle the integer handle of the user, where 0 is the primary user. 1744 * @hide 1745 */ 1746 public boolean removeUser(@UserIdInt int userHandle) { 1747 try { 1748 return mService.removeUser(userHandle); 1749 } catch (RemoteException re) { 1750 throw re.rethrowFromSystemServer(); 1751 } 1752 } 1753 1754 /** 1755 * Updates the user's name. 1756 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1757 * 1758 * @param userHandle the user's integer handle 1759 * @param name the new name for the user 1760 * @hide 1761 */ 1762 public void setUserName(@UserIdInt int userHandle, String name) { 1763 try { 1764 mService.setUserName(userHandle, name); 1765 } catch (RemoteException re) { 1766 throw re.rethrowFromSystemServer(); 1767 } 1768 } 1769 1770 /** 1771 * Sets the user's photo. 1772 * @param userHandle the user for whom to change the photo. 1773 * @param icon the bitmap to set as the photo. 1774 * @hide 1775 */ 1776 public void setUserIcon(@UserIdInt int userHandle, Bitmap icon) { 1777 try { 1778 mService.setUserIcon(userHandle, icon); 1779 } catch (RemoteException re) { 1780 throw re.rethrowFromSystemServer(); 1781 } 1782 } 1783 1784 /** 1785 * Returns a file descriptor for the user's photo. PNG data can be read from this file. 1786 * @param userHandle the user whose photo we want to read. 1787 * @return a {@link Bitmap} of the user's photo, or null if there's no photo. 1788 * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default. 1789 * @hide 1790 */ 1791 public Bitmap getUserIcon(@UserIdInt int userHandle) { 1792 try { 1793 ParcelFileDescriptor fd = mService.getUserIcon(userHandle); 1794 if (fd != null) { 1795 try { 1796 return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor()); 1797 } finally { 1798 try { 1799 fd.close(); 1800 } catch (IOException e) { 1801 } 1802 } 1803 } 1804 } catch (RemoteException re) { 1805 throw re.rethrowFromSystemServer(); 1806 } 1807 return null; 1808 } 1809 1810 /** 1811 * Returns the maximum number of users that can be created on this device. A return value 1812 * of 1 means that it is a single user device. 1813 * @hide 1814 * @return a value greater than or equal to 1 1815 */ 1816 public static int getMaxSupportedUsers() { 1817 // Don't allow multiple users on certain builds 1818 if (android.os.Build.ID.startsWith("JVP")) return 1; 1819 // Svelte devices don't get multi-user. 1820 if (ActivityManager.isLowRamDeviceStatic()) return 1; 1821 return SystemProperties.getInt("fw.max_users", 1822 Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers)); 1823 } 1824 1825 /** 1826 * Returns true if the user switcher should be shown, this will be if device supports multi-user 1827 * and there are at least 2 users available that are not managed profiles. 1828 * @hide 1829 * @return true if user switcher should be shown. 1830 */ 1831 public boolean isUserSwitcherEnabled() { 1832 if (!supportsMultipleUsers()) { 1833 return false; 1834 } 1835 List<UserInfo> users = getUsers(true); 1836 if (users == null) { 1837 return false; 1838 } 1839 int switchableUserCount = 0; 1840 for (UserInfo user : users) { 1841 if (user.supportsSwitchToByUser()) { 1842 ++switchableUserCount; 1843 } 1844 } 1845 final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class) 1846 .getGuestUserDisabled(null); 1847 return switchableUserCount > 1 || guestEnabled; 1848 } 1849 1850 /** 1851 * Returns a serial number on this device for a given userHandle. User handles can be recycled 1852 * when deleting and creating users, but serial numbers are not reused until the device is wiped. 1853 * @param userHandle 1854 * @return a serial number associated with that user, or -1 if the userHandle is not valid. 1855 * @hide 1856 */ 1857 public int getUserSerialNumber(@UserIdInt int userHandle) { 1858 try { 1859 return mService.getUserSerialNumber(userHandle); 1860 } catch (RemoteException re) { 1861 throw re.rethrowFromSystemServer(); 1862 } 1863 } 1864 1865 /** 1866 * Returns a userHandle on this device for a given user serial number. User handles can be 1867 * recycled when deleting and creating users, but serial numbers are not reused until the device 1868 * is wiped. 1869 * @param userSerialNumber 1870 * @return the userHandle associated with that user serial number, or -1 if the serial number 1871 * is not valid. 1872 * @hide 1873 */ 1874 public @UserIdInt int getUserHandle(int userSerialNumber) { 1875 try { 1876 return mService.getUserHandle(userSerialNumber); 1877 } catch (RemoteException re) { 1878 throw re.rethrowFromSystemServer(); 1879 } 1880 } 1881 1882 /** 1883 * Returns a {@code Bundle} containing any saved application restrictions for this user, for the 1884 * given package name. Only an application with this package name can call this method. 1885 * 1886 * <p>The returned {@link Bundle} consists of key-value pairs, as defined by the application, 1887 * where the types of values may be: 1888 * <ul> 1889 * <li>{@code boolean} 1890 * <li>{@code int} 1891 * <li>{@code String} or {@code String[]} 1892 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} 1893 * </ul> 1894 * 1895 * @param packageName the package name of the calling application 1896 * @return a {@code Bundle} with the restrictions for that package, or {@code null} if there 1897 * are no saved restrictions. 1898 * 1899 * @see #KEY_RESTRICTIONS_PENDING 1900 */ 1901 public Bundle getApplicationRestrictions(String packageName) { 1902 try { 1903 return mService.getApplicationRestrictions(packageName); 1904 } catch (RemoteException re) { 1905 throw re.rethrowFromSystemServer(); 1906 } 1907 } 1908 1909 /** 1910 * @hide 1911 */ 1912 public Bundle getApplicationRestrictions(String packageName, UserHandle user) { 1913 try { 1914 return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier()); 1915 } catch (RemoteException re) { 1916 throw re.rethrowFromSystemServer(); 1917 } 1918 } 1919 1920 /** 1921 * @hide 1922 */ 1923 public void setApplicationRestrictions(String packageName, Bundle restrictions, 1924 UserHandle user) { 1925 try { 1926 mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier()); 1927 } catch (RemoteException re) { 1928 throw re.rethrowFromSystemServer(); 1929 } 1930 } 1931 1932 /** 1933 * Sets a new challenge PIN for restrictions. This is only for use by pre-installed 1934 * apps and requires the MANAGE_USERS permission. 1935 * @param newPin the PIN to use for challenge dialogs. 1936 * @return Returns true if the challenge PIN was set successfully. 1937 * @deprecated The restrictions PIN functionality is no longer provided by the system. 1938 * This method is preserved for backwards compatibility reasons and always returns false. 1939 */ 1940 public boolean setRestrictionsChallenge(String newPin) { 1941 return false; 1942 } 1943 1944 /** 1945 * @hide 1946 * Set restrictions that should apply to any future guest user that's created. 1947 */ 1948 public void setDefaultGuestRestrictions(Bundle restrictions) { 1949 try { 1950 mService.setDefaultGuestRestrictions(restrictions); 1951 } catch (RemoteException re) { 1952 throw re.rethrowFromSystemServer(); 1953 } 1954 } 1955 1956 /** 1957 * @hide 1958 * Gets the default guest restrictions. 1959 */ 1960 public Bundle getDefaultGuestRestrictions() { 1961 try { 1962 return mService.getDefaultGuestRestrictions(); 1963 } catch (RemoteException re) { 1964 throw re.rethrowFromSystemServer(); 1965 } 1966 } 1967 1968 /** 1969 * Returns creation time of the user or of a managed profile associated with the calling user. 1970 * @param userHandle user handle of the user or a managed profile associated with the 1971 * calling user. 1972 * @return creation time in milliseconds since Epoch time. 1973 */ 1974 public long getUserCreationTime(UserHandle userHandle) { 1975 try { 1976 return mService.getUserCreationTime(userHandle.getIdentifier()); 1977 } catch (RemoteException re) { 1978 throw re.rethrowFromSystemServer(); 1979 } 1980 } 1981 1982 /** 1983 * @hide 1984 * Checks if any uninitialized user has the specific seed account name and type. 1985 * 1986 * @param mAccountName The account name to check for 1987 * @param mAccountType The account type of the account to check for 1988 * @return whether the seed account was found 1989 */ 1990 public boolean someUserHasSeedAccount(String accountName, String accountType) { 1991 try { 1992 return mService.someUserHasSeedAccount(accountName, accountType); 1993 } catch (RemoteException re) { 1994 throw re.rethrowFromSystemServer(); 1995 } 1996 } 1997} 1998