diff options
| author | Mayank Garg <gargmayank@google.com> | 2022-02-27 10:48:48 -0800 |
|---|---|---|
| committer | Mayank Garg <gargmayank@google.com> | 2022-03-09 03:10:26 +0000 |
| commit | ad9fe6df52baf59cb501abbef0b12bb0679c81cd (patch) | |
| tree | 3cb72b89a11e437e1ffcf10b8aaa736fade16d9e /core/java/android/os/UserManager.java | |
| parent | 11a44a2ca493afbe23cd218f366cba71de8d3da4 (diff) | |
Improved error code for Remove Result
Bug: 215555912
Test: atest UserManagerTest
Change-Id: If92e9a3fcc042236c89ec13e691412dbb6a18a66
Diffstat (limited to 'core/java/android/os/UserManager.java')
| -rw-r--r-- | core/java/android/os/UserManager.java | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java index e56f214e30d9..1b5f476346d3 100644 --- a/core/java/android/os/UserManager.java +++ b/core/java/android/os/UserManager.java @@ -1703,12 +1703,40 @@ public class UserManager { /** * A response code from {@link #removeUserWhenPossible(UserHandle, boolean)} indicating that - * an error occurred that prevented the user from being removed or set as ephemeral. + * an unknown error occurred that prevented the user from being removed or set as ephemeral. * * @hide */ @SystemApi - public static final int REMOVE_RESULT_ERROR = 3; + public static final int REMOVE_RESULT_ERROR_UNKNOWN = -1; + + /** + * A response code from {@link #removeUserWhenPossible(UserHandle, boolean)} indicating that + * the user could not be removed due to a {@link #DISALLOW_REMOVE_MANAGED_PROFILE} or + * {@link #DISALLOW_REMOVE_USER} user restriction. + * + * @hide + */ + @SystemApi + public static final int REMOVE_RESULT_ERROR_USER_RESTRICTION = -2; + + /** + * A response code from {@link #removeUserWhenPossible(UserHandle, boolean)} indicating that + * user being removed does not exist. + * + * @hide + */ + @SystemApi + public static final int REMOVE_RESULT_ERROR_USER_NOT_FOUND = -3; + + /** + * A response code from {@link #removeUserWhenPossible(UserHandle, boolean)} indicating that + * user being removed is a {@link UserHandle#SYSTEM} user which can't be removed. + * + * @hide + */ + @SystemApi + public static final int REMOVE_RESULT_ERROR_SYSTEM_USER = -4; /** * Possible response codes from {@link #removeUserWhenPossible(UserHandle, boolean)}. @@ -1719,7 +1747,10 @@ public class UserManager { REMOVE_RESULT_REMOVED, REMOVE_RESULT_DEFERRED, REMOVE_RESULT_ALREADY_BEING_REMOVED, - REMOVE_RESULT_ERROR, + REMOVE_RESULT_ERROR_USER_RESTRICTION, + REMOVE_RESULT_ERROR_USER_NOT_FOUND, + REMOVE_RESULT_ERROR_SYSTEM_USER, + REMOVE_RESULT_ERROR_UNKNOWN, }) @Retention(RetentionPolicy.SOURCE) public @interface RemoveResult {} @@ -4842,8 +4873,10 @@ public class UserManager { * the {@link #DISALLOW_REMOVE_USER} or {@link #DISALLOW_REMOVE_MANAGED_PROFILE} restriction * * @return the {@link RemoveResult} code: {@link #REMOVE_RESULT_REMOVED}, - * {@link #REMOVE_RESULT_DEFERRED}, {@link #REMOVE_RESULT_ALREADY_BEING_REMOVED}, or - * {@link #REMOVE_RESULT_ERROR}. + * {@link #REMOVE_RESULT_DEFERRED}, {@link #REMOVE_RESULT_ALREADY_BEING_REMOVED}, + * {@link #REMOVE_RESULT_ERROR_USER_RESTRICTION}, {@link #REMOVE_RESULT_ERROR_USER_NOT_FOUND}, + * {@link #REMOVE_RESULT_ERROR_SYSTEM_USER}, or {@link #REMOVE_RESULT_ERROR_UNKNOWN}. All error + * codes have negative values. * * @hide */ @@ -4860,6 +4893,19 @@ public class UserManager { } /** + * Check if {@link #removeUserWhenPossible} returned a success code which means that the user + * has been removed or is slated for removal. + * + * @param result is {@link #RemoveResult} code return by {@link #removeUserWhenPossible}. + * @return {@code true} if it is a success code. + * @hide + */ + @SystemApi + public static boolean isRemoveResultSuccessful(@RemoveResult int result) { + return result >= 0; + } + + /** * Updates the user's name. * * @param userId the user's integer id |
