UserManager.java revision 2a764949c943681a4d25a17a0b203a0127a4a486
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.app.ActivityManagerNative; 19import android.content.Context; 20import android.content.pm.UserInfo; 21import android.content.res.Resources; 22import android.graphics.Bitmap; 23import android.util.Log; 24 25import com.android.internal.R; 26 27import java.util.List; 28 29/** 30 * Manages users and user details on a multi-user system. 31 */ 32public class UserManager { 33 34 private static String TAG = "UserManager"; 35 private final IUserManager mService; 36 private final Context mContext; 37 38 /** 39 * Key for user restrictions. Specifies if a user is disallowed from adding and removing 40 * accounts. 41 * The default value is <code>false</code>. 42 * <p/> 43 * Type: Boolean 44 * @see #setUserRestrictions(Bundle) 45 * @see #getUserRestrictions() 46 */ 47 public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts"; 48 49 /** 50 * Key for user restrictions. Specifies if a user is disallowed from changing Wi-Fi 51 * access points. 52 * The default value is <code>false</code>. 53 * <p/> 54 * Type: Boolean 55 * @see #setUserRestrictions(Bundle) 56 * @see #getUserRestrictions() 57 */ 58 public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi"; 59 60 /** 61 * Key for user restrictions. Specifies if a user is disallowed from installing applications. 62 * The default value is <code>false</code>. 63 * <p/> 64 * Type: Boolean 65 * @see #setUserRestrictions(Bundle) 66 * @see #getUserRestrictions() 67 */ 68 public static final String DISALLOW_INSTALL_APPS = "no_install_apps"; 69 70 /** 71 * Key for user restrictions. Specifies if a user is disallowed from uninstalling applications. 72 * The default value is <code>false</code>. 73 * <p/> 74 * Type: Boolean 75 * @see #setUserRestrictions(Bundle) 76 * @see #getUserRestrictions() 77 */ 78 public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps"; 79 80 /** 81 * Key for user restrictions. Specifies if a user is disallowed from toggling location sharing. 82 * The default value is <code>false</code>. 83 * <p/> 84 * Type: Boolean 85 * @see #setUserRestrictions(Bundle) 86 * @see #getUserRestrictions() 87 */ 88 89 public static final String DISALLOW_SHARE_LOCATION = "no_share_location"; 90 91 /** 92 * Key for user restrictions. Specifies if a user is disallowed from enabling the 93 * "Unknown Sources" setting, that allows installation of apps from unknown sources. 94 * The default value is <code>false</code>. 95 * <p/> 96 * Type: Boolean 97 * @see #setUserRestrictions(Bundle) 98 * @see #getUserRestrictions() 99 */ 100 public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources"; 101 102 /** 103 * Key for user restrictions. Specifies if a user is disallowed from configuring bluetooth. 104 * The default value is <code>false</code>. 105 * <p/> 106 * Type: Boolean 107 * @see #setUserRestrictions(Bundle) 108 * @see #getUserRestrictions() 109 */ 110 public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth"; 111 112 /** 113 * Key for user restrictions. Specifies if a user is disallowed from transferring files over 114 * USB. The default value is <code>false</code>. 115 * <p/> 116 * Type: Boolean 117 * @see #setUserRestrictions(Bundle) 118 * @see #getUserRestrictions() 119 */ 120 public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer"; 121 122 /** 123 * Key for user restrictions. Specifies if a user is disallowed from configuring user 124 * credentials. The default value is <code>false</code>. 125 * <p/> 126 * Type: Boolean 127 * @see #setUserRestrictions(Bundle) 128 * @see #getUserRestrictions() 129 */ 130 public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials"; 131 132 /** 133 * Key for user restrictions. Specifies if a user is disallowed from removing users. 134 * The default value is <code>false</code>. 135 * <p/> 136 * Type: Boolean 137 * @see #setUserRestrictions(Bundle) 138 * @see #getUserRestrictions() 139 */ 140 public static final String DISALLOW_REMOVE_USER = "no_remove_user"; 141 142 /** @hide */ 143 public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3; 144 /** @hide */ 145 public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2; 146 /** @hide */ 147 public static final int PIN_VERIFICATION_SUCCESS = -1; 148 149 private static UserManager sInstance = null; 150 151 /** @hide */ 152 public synchronized static UserManager get(Context context) { 153 if (sInstance == null) { 154 sInstance = (UserManager) context.getSystemService(Context.USER_SERVICE); 155 } 156 return sInstance; 157 } 158 159 /** @hide */ 160 public UserManager(Context context, IUserManager service) { 161 mService = service; 162 mContext = context; 163 } 164 165 /** 166 * Returns whether the system supports multiple users. 167 * @return true if multiple users can be created by user, false if it is a single user device. 168 * @hide 169 */ 170 public static boolean supportsMultipleUsers() { 171 return getMaxSupportedUsers() > 1 172 && SystemProperties.getBoolean("fw.show_multiuserui", 173 Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI)); 174 } 175 176 /** 177 * Returns the user handle for the user that this application is running for. 178 * @return the user handle of the user making this call. 179 * @hide 180 */ 181 public int getUserHandle() { 182 return UserHandle.myUserId(); 183 } 184 185 /** 186 * Returns the user name of the user making this call. This call is only 187 * available to applications on the system image; it requires the 188 * MANAGE_USERS permission. 189 * @return the user name 190 */ 191 public String getUserName() { 192 try { 193 return mService.getUserInfo(getUserHandle()).name; 194 } catch (RemoteException re) { 195 Log.w(TAG, "Could not get user name", re); 196 return ""; 197 } 198 } 199 200 /** 201 * Used to determine whether the user making this call is subject to 202 * teleportations. 203 * @return whether the user making this call is a goat 204 */ 205 public boolean isUserAGoat() { 206 return false; 207 } 208 209 /** 210 * Used to check if the user making this call is linked to another user. Linked users may have 211 * a reduced number of available apps, app restrictions and account restrictions. 212 * @return whether the user making this call is a linked user 213 * @hide 214 */ 215 public boolean isLinkedUser() { 216 try { 217 return mService.isRestricted(); 218 } catch (RemoteException re) { 219 Log.w(TAG, "Could not check if user is limited ", re); 220 return false; 221 } 222 } 223 224 /** 225 * Return whether the given user is actively running. This means that 226 * the user is in the "started" state, not "stopped" -- it is currently 227 * allowed to run code through scheduled alarms, receiving broadcasts, 228 * etc. A started user may be either the current foreground user or a 229 * background user; the result here does not distinguish between the two. 230 * @param user The user to retrieve the running state for. 231 */ 232 public boolean isUserRunning(UserHandle user) { 233 try { 234 return ActivityManagerNative.getDefault().isUserRunning( 235 user.getIdentifier(), false); 236 } catch (RemoteException e) { 237 return false; 238 } 239 } 240 241 /** 242 * Return whether the given user is actively running <em>or</em> stopping. 243 * This is like {@link #isUserRunning(UserHandle)}, but will also return 244 * true if the user had been running but is in the process of being stopped 245 * (but is not yet fully stopped, and still running some code). 246 * @param user The user to retrieve the running state for. 247 */ 248 public boolean isUserRunningOrStopping(UserHandle user) { 249 try { 250 return ActivityManagerNative.getDefault().isUserRunning( 251 user.getIdentifier(), true); 252 } catch (RemoteException e) { 253 return false; 254 } 255 } 256 257 /** 258 * Returns the UserInfo object describing a specific user. 259 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 260 * @param userHandle the user handle of the user whose information is being requested. 261 * @return the UserInfo object for a specific user. 262 * @hide 263 */ 264 public UserInfo getUserInfo(int userHandle) { 265 try { 266 return mService.getUserInfo(userHandle); 267 } catch (RemoteException re) { 268 Log.w(TAG, "Could not get user info", re); 269 return null; 270 } 271 } 272 273 /** 274 * Returns the user-wide restrictions imposed on this user. 275 * @return a Bundle containing all the restrictions. 276 */ 277 public Bundle getUserRestrictions() { 278 return getUserRestrictions(Process.myUserHandle()); 279 } 280 281 /** 282 * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>. 283 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 284 * @return a Bundle containing all the restrictions. 285 */ 286 public Bundle getUserRestrictions(UserHandle userHandle) { 287 try { 288 return mService.getUserRestrictions(userHandle.getIdentifier()); 289 } catch (RemoteException re) { 290 Log.w(TAG, "Could not get user restrictions", re); 291 return Bundle.EMPTY; 292 } 293 } 294 295 /** 296 * Sets all the user-wide restrictions for this user. 297 * Requires the MANAGE_USERS permission. 298 * @param restrictions the Bundle containing all the restrictions. 299 */ 300 public void setUserRestrictions(Bundle restrictions) { 301 setUserRestrictions(restrictions, Process.myUserHandle()); 302 } 303 304 /** 305 * Sets all the user-wide restrictions for the specified user. 306 * Requires the MANAGE_USERS permission. 307 * @param restrictions the Bundle containing all the restrictions. 308 * @param userHandle the UserHandle of the user for whom to set the restrictions. 309 */ 310 public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) { 311 try { 312 mService.setUserRestrictions(restrictions, userHandle.getIdentifier()); 313 } catch (RemoteException re) { 314 Log.w(TAG, "Could not set user restrictions", re); 315 } 316 } 317 318 /** 319 * Sets the value of a specific restriction. 320 * Requires the MANAGE_USERS permission. 321 * @param key the key of the restriction 322 * @param value the value for the restriction 323 */ 324 public void setUserRestriction(String key, boolean value) { 325 Bundle bundle = getUserRestrictions(); 326 bundle.putBoolean(key, value); 327 setUserRestrictions(bundle); 328 } 329 330 /** 331 * @hide 332 * Sets the value of a specific restriction on a specific user. 333 * Requires the {@link android.Manifest.permission#MANAGE_USERS} permission. 334 * @param key the key of the restriction 335 * @param value the value for the restriction 336 * @param userHandle the user whose restriction is to be changed. 337 */ 338 public void setUserRestriction(String key, boolean value, UserHandle userHandle) { 339 Bundle bundle = getUserRestrictions(userHandle); 340 bundle.putBoolean(key, value); 341 setUserRestrictions(bundle, userHandle); 342 } 343 344 /** 345 * @hide 346 * Returns whether the current user has been disallowed from performing certain actions 347 * or setting certain settings. 348 * @param restrictionKey the string key representing the restriction 349 */ 350 public boolean hasUserRestriction(String restrictionKey) { 351 return hasUserRestriction(restrictionKey, Process.myUserHandle()); 352 } 353 354 /** 355 * @hide 356 * Returns whether the given user has been disallowed from performing certain actions 357 * or setting certain settings. 358 * @param restrictionKey the string key representing the restriction 359 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 360 */ 361 public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) { 362 return getUserRestrictions(userHandle).getBoolean(restrictionKey, false); 363 } 364 365 /** 366 * Return the serial number for a user. This is a device-unique 367 * number assigned to that user; if the user is deleted and then a new 368 * user created, the new users will not be given the same serial number. 369 * @param user The user whose serial number is to be retrieved. 370 * @return The serial number of the given user; returns -1 if the 371 * given UserHandle does not exist. 372 * @see #getUserForSerialNumber(long) 373 */ 374 public long getSerialNumberForUser(UserHandle user) { 375 return getUserSerialNumber(user.getIdentifier()); 376 } 377 378 /** 379 * Return the user associated with a serial number previously 380 * returned by {@link #getSerialNumberForUser(UserHandle)}. 381 * @param serialNumber The serial number of the user that is being 382 * retrieved. 383 * @return Return the user associated with the serial number, or null 384 * if there is not one. 385 * @see #getSerialNumberForUser(UserHandle) 386 */ 387 public UserHandle getUserForSerialNumber(long serialNumber) { 388 int ident = getUserHandle((int)serialNumber); 389 return ident >= 0 ? new UserHandle(ident) : null; 390 } 391 392 /** 393 * Creates a user with the specified name and options. 394 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 395 * 396 * @param name the user's name 397 * @param flags flags that identify the type of user and other properties. 398 * @see UserInfo 399 * 400 * @return the UserInfo object for the created user, or null if the user could not be created. 401 * @hide 402 */ 403 public UserInfo createUser(String name, int flags) { 404 try { 405 return mService.createUser(name, flags); 406 } catch (RemoteException re) { 407 Log.w(TAG, "Could not create a user", re); 408 return null; 409 } 410 } 411 412 /** 413 * Renamed, just present to avoid multi project commit. 414 * TODO delete. 415 * @hide 416 */ 417 public UserInfo createRelatedUser(String name, int flags, int relatedUserId) { 418 return createProfileForUser(name, flags, relatedUserId); 419 } 420 421 /** 422 * Creates a user with the specified name and options as a profile of another user. 423 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 424 * 425 * @param name the user's name 426 * @param flags flags that identify the type of user and other properties. 427 * @see UserInfo 428 * @param userHandle new user will be a profile of this use. 429 * 430 * @return the UserInfo object for the created user, or null if the user could not be created. 431 * @hide 432 */ 433 public UserInfo createProfileForUser(String name, int flags, int userHandle) { 434 try { 435 return mService.createProfileForUser(name, flags, userHandle); 436 } catch (RemoteException re) { 437 Log.w(TAG, "Could not create a user", re); 438 return null; 439 } 440 } 441 442 /** 443 * Return the number of users currently created on the device. 444 */ 445 public int getUserCount() { 446 List<UserInfo> users = getUsers(); 447 return users != null ? users.size() : 1; 448 } 449 450 /** 451 * Returns information for all users on this device. 452 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 453 * @return the list of users that were created. 454 * @hide 455 */ 456 public List<UserInfo> getUsers() { 457 try { 458 return mService.getUsers(false); 459 } catch (RemoteException re) { 460 Log.w(TAG, "Could not get user list", re); 461 return null; 462 } 463 } 464 465 /** 466 * Renaming, left to avoid multi project commit. 467 * TODO Delete. 468 * @hide 469 */ 470 public List<UserInfo> getRelatedUsers(int userHandle) { 471 return getProfiles(userHandle); 472 } 473 474 /** 475 * Returns list of the profiles of userHandle including 476 * userHandle itself. 477 * 478 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 479 * @param userHandle profiles of this user will be returned. 480 * @return the list of profiles. 481 * @hide 482 */ 483 public List<UserInfo> getProfiles(int userHandle) { 484 try { 485 return mService.getProfiles(userHandle); 486 } catch (RemoteException re) { 487 Log.w(TAG, "Could not get user list", re); 488 return null; 489 } 490 } 491 492 /** 493 * Returns information for all users on this device. 494 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 495 * @param excludeDying specify if the list should exclude users being removed. 496 * @return the list of users that were created. 497 * @hide 498 */ 499 public List<UserInfo> getUsers(boolean excludeDying) { 500 try { 501 return mService.getUsers(excludeDying); 502 } catch (RemoteException re) { 503 Log.w(TAG, "Could not get user list", re); 504 return null; 505 } 506 } 507 508 /** 509 * Removes a user and all associated data. 510 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 511 * @param userHandle the integer handle of the user, where 0 is the primary user. 512 * @hide 513 */ 514 public boolean removeUser(int userHandle) { 515 try { 516 return mService.removeUser(userHandle); 517 } catch (RemoteException re) { 518 Log.w(TAG, "Could not remove user ", re); 519 return false; 520 } 521 } 522 523 /** 524 * Updates the user's name. 525 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 526 * 527 * @param userHandle the user's integer handle 528 * @param name the new name for the user 529 * @hide 530 */ 531 public void setUserName(int userHandle, String name) { 532 try { 533 mService.setUserName(userHandle, name); 534 } catch (RemoteException re) { 535 Log.w(TAG, "Could not set the user name ", re); 536 } 537 } 538 539 /** 540 * Sets the user's photo. 541 * @param userHandle the user for whom to change the photo. 542 * @param icon the bitmap to set as the photo. 543 * @hide 544 */ 545 public void setUserIcon(int userHandle, Bitmap icon) { 546 try { 547 mService.setUserIcon(userHandle, icon); 548 } catch (RemoteException re) { 549 Log.w(TAG, "Could not set the user icon ", re); 550 } 551 } 552 553 /** 554 * Returns a file descriptor for the user's photo. PNG data can be read from this file. 555 * @param userHandle the user whose photo we want to read. 556 * @return a {@link Bitmap} of the user's photo, or null if there's no photo. 557 * @hide 558 */ 559 public Bitmap getUserIcon(int userHandle) { 560 try { 561 return mService.getUserIcon(userHandle); 562 } catch (RemoteException re) { 563 Log.w(TAG, "Could not get the user icon ", re); 564 return null; 565 } 566 } 567 568 /** 569 * Enable or disable the use of a guest account. If disabled, the existing guest account 570 * will be wiped. 571 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 572 * @param enable whether to enable a guest account. 573 * @hide 574 */ 575 public void setGuestEnabled(boolean enable) { 576 try { 577 mService.setGuestEnabled(enable); 578 } catch (RemoteException re) { 579 Log.w(TAG, "Could not change guest account availability to " + enable); 580 } 581 } 582 583 /** 584 * Checks if a guest user is enabled for this device. 585 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 586 * @return whether a guest user is enabled 587 * @hide 588 */ 589 public boolean isGuestEnabled() { 590 try { 591 return mService.isGuestEnabled(); 592 } catch (RemoteException re) { 593 Log.w(TAG, "Could not retrieve guest enabled state"); 594 return false; 595 } 596 } 597 598 /** 599 * Wipes all the data for a user, but doesn't remove the user. 600 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 601 * @param userHandle 602 * @hide 603 */ 604 public void wipeUser(int userHandle) { 605 try { 606 mService.wipeUser(userHandle); 607 } catch (RemoteException re) { 608 Log.w(TAG, "Could not wipe user " + userHandle); 609 } 610 } 611 612 /** 613 * Returns the maximum number of users that can be created on this device. A return value 614 * of 1 means that it is a single user device. 615 * @hide 616 * @return a value greater than or equal to 1 617 */ 618 public static int getMaxSupportedUsers() { 619 // Don't allow multiple users on certain builds 620 if (android.os.Build.ID.startsWith("JVP")) return 1; 621 return SystemProperties.getInt("fw.max_users", 622 Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers)); 623 } 624 625 /** 626 * Returns true if the user switcher should be shown, this will be if there 627 * are multiple users that aren't managed profiles. 628 * @hide 629 * @return true if user switcher should be shown. 630 */ 631 public boolean isUserSwitcherEnabled() { 632 List<UserInfo> users = getUsers(true); 633 if (users == null) { 634 return false; 635 } 636 int switchableUserCount = 0; 637 for (UserInfo user : users) { 638 if (user.supportsSwitchTo()) { 639 ++switchableUserCount; 640 } 641 } 642 return switchableUserCount > 1; 643 } 644 645 /** 646 * Returns a serial number on this device for a given userHandle. User handles can be recycled 647 * when deleting and creating users, but serial numbers are not reused until the device is wiped. 648 * @param userHandle 649 * @return a serial number associated with that user, or -1 if the userHandle is not valid. 650 * @hide 651 */ 652 public int getUserSerialNumber(int userHandle) { 653 try { 654 return mService.getUserSerialNumber(userHandle); 655 } catch (RemoteException re) { 656 Log.w(TAG, "Could not get serial number for user " + userHandle); 657 } 658 return -1; 659 } 660 661 /** 662 * Returns a userHandle on this device for a given user serial number. User handles can be 663 * recycled when deleting and creating users, but serial numbers are not reused until the device 664 * is wiped. 665 * @param userSerialNumber 666 * @return the userHandle associated with that user serial number, or -1 if the serial number 667 * is not valid. 668 * @hide 669 */ 670 public int getUserHandle(int userSerialNumber) { 671 try { 672 return mService.getUserHandle(userSerialNumber); 673 } catch (RemoteException re) { 674 Log.w(TAG, "Could not get userHandle for user " + userSerialNumber); 675 } 676 return -1; 677 } 678 679 /** 680 * Returns a Bundle containing any saved application restrictions for this user, for the 681 * given package name. Only an application with this package name can call this method. 682 * @param packageName the package name of the calling application 683 * @return a Bundle with the restrictions as key/value pairs, or null if there are no 684 * saved restrictions. The values can be of type Boolean, String or String[], depending 685 * on the restriction type, as defined by the application. 686 */ 687 public Bundle getApplicationRestrictions(String packageName) { 688 try { 689 return mService.getApplicationRestrictions(packageName); 690 } catch (RemoteException re) { 691 Log.w(TAG, "Could not get application restrictions for package " + packageName); 692 } 693 return null; 694 } 695 696 /** 697 * @hide 698 */ 699 public Bundle getApplicationRestrictions(String packageName, UserHandle user) { 700 try { 701 return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier()); 702 } catch (RemoteException re) { 703 Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier()); 704 } 705 return null; 706 } 707 708 /** 709 * @hide 710 */ 711 public void setApplicationRestrictions(String packageName, Bundle restrictions, 712 UserHandle user) { 713 try { 714 mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier()); 715 } catch (RemoteException re) { 716 Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier()); 717 } 718 } 719 720 /** 721 * Sets a new challenge PIN for restrictions. This is only for use by pre-installed 722 * apps and requires the MANAGE_USERS permission. 723 * @param newPin the PIN to use for challenge dialogs. 724 * @return Returns true if the challenge PIN was set successfully. 725 */ 726 public boolean setRestrictionsChallenge(String newPin) { 727 try { 728 return mService.setRestrictionsChallenge(newPin); 729 } catch (RemoteException re) { 730 Log.w(TAG, "Could not change restrictions pin"); 731 } 732 return false; 733 } 734 735 /** 736 * @hide 737 * @param pin The PIN to verify, or null to get the number of milliseconds to wait for before 738 * allowing the user to enter the PIN. 739 * @return Returns a positive number (including zero) for how many milliseconds before 740 * you can accept another PIN, when the input is null or the input doesn't match the saved PIN. 741 * Returns {@link #PIN_VERIFICATION_SUCCESS} if the input matches the saved PIN. Returns 742 * {@link #PIN_VERIFICATION_FAILED_NOT_SET} if there is no PIN set. 743 */ 744 public int checkRestrictionsChallenge(String pin) { 745 try { 746 return mService.checkRestrictionsChallenge(pin); 747 } catch (RemoteException re) { 748 Log.w(TAG, "Could not check restrictions pin"); 749 } 750 return PIN_VERIFICATION_FAILED_INCORRECT; 751 } 752 753 /** 754 * @hide 755 * Checks whether the user has restrictions that are PIN-protected. An application that 756 * participates in restrictions can check if the owner has requested a PIN challenge for 757 * any restricted operations. If there is a PIN in effect, the application should launch 758 * the PIN challenge activity {@link android.content.Intent#ACTION_RESTRICTIONS_CHALLENGE}. 759 * @see android.content.Intent#ACTION_RESTRICTIONS_CHALLENGE 760 * @return whether a restrictions PIN is in effect. 761 */ 762 public boolean hasRestrictionsChallenge() { 763 try { 764 return mService.hasRestrictionsChallenge(); 765 } catch (RemoteException re) { 766 Log.w(TAG, "Could not change restrictions pin"); 767 } 768 return false; 769 } 770 771 /** @hide */ 772 public void removeRestrictions() { 773 try { 774 mService.removeRestrictions(); 775 } catch (RemoteException re) { 776 Log.w(TAG, "Could not change restrictions pin"); 777 } 778 } 779} 780