Merge "Improved error code for Remove Result" into tm-dev
This commit is contained in:
@@ -9791,6 +9791,7 @@ package android.os {
|
|||||||
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.QUERY_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional=true) public boolean isManagedProfile(int);
|
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.QUERY_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional=true) public boolean isManagedProfile(int);
|
||||||
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional=true) public boolean isMediaSharedWithParent();
|
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional=true) public boolean isMediaSharedWithParent();
|
||||||
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS, android.Manifest.permission.QUERY_USERS}) public boolean isPrimaryUser();
|
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS, android.Manifest.permission.QUERY_USERS}) public boolean isPrimaryUser();
|
||||||
|
method public static boolean isRemoveResultSuccessful(int);
|
||||||
method public boolean isRestrictedProfile();
|
method public boolean isRestrictedProfile();
|
||||||
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}, conditional=true) public boolean isRestrictedProfile(@NonNull android.os.UserHandle);
|
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}, conditional=true) public boolean isRestrictedProfile(@NonNull android.os.UserHandle);
|
||||||
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.QUERY_USERS}) public boolean isSameProfileGroup(@NonNull android.os.UserHandle, @NonNull android.os.UserHandle);
|
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.QUERY_USERS}) public boolean isSameProfileGroup(@NonNull android.os.UserHandle, @NonNull android.os.UserHandle);
|
||||||
@@ -9808,7 +9809,10 @@ package android.os {
|
|||||||
field public static final String DISALLOW_RUN_IN_BACKGROUND = "no_run_in_background";
|
field public static final String DISALLOW_RUN_IN_BACKGROUND = "no_run_in_background";
|
||||||
field public static final int REMOVE_RESULT_ALREADY_BEING_REMOVED = 2; // 0x2
|
field public static final int REMOVE_RESULT_ALREADY_BEING_REMOVED = 2; // 0x2
|
||||||
field public static final int REMOVE_RESULT_DEFERRED = 1; // 0x1
|
field public static final int REMOVE_RESULT_DEFERRED = 1; // 0x1
|
||||||
field public static final int REMOVE_RESULT_ERROR = 3; // 0x3
|
field public static final int REMOVE_RESULT_ERROR_SYSTEM_USER = -4; // 0xfffffffc
|
||||||
|
field public static final int REMOVE_RESULT_ERROR_UNKNOWN = -1; // 0xffffffff
|
||||||
|
field public static final int REMOVE_RESULT_ERROR_USER_NOT_FOUND = -3; // 0xfffffffd
|
||||||
|
field public static final int REMOVE_RESULT_ERROR_USER_RESTRICTION = -2; // 0xfffffffe
|
||||||
field public static final int REMOVE_RESULT_REMOVED = 0; // 0x0
|
field public static final int REMOVE_RESULT_REMOVED = 0; // 0x0
|
||||||
field public static final int RESTRICTION_NOT_SET = 0; // 0x0
|
field public static final int RESTRICTION_NOT_SET = 0; // 0x0
|
||||||
field public static final int RESTRICTION_SOURCE_DEVICE_OWNER = 2; // 0x2
|
field public static final int RESTRICTION_SOURCE_DEVICE_OWNER = 2; // 0x2
|
||||||
|
|||||||
@@ -1703,12 +1703,40 @@ public class UserManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A response code from {@link #removeUserWhenPossible(UserHandle, boolean)} indicating that
|
* 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
|
* @hide
|
||||||
*/
|
*/
|
||||||
@SystemApi
|
@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)}.
|
* Possible response codes from {@link #removeUserWhenPossible(UserHandle, boolean)}.
|
||||||
@@ -1719,7 +1747,10 @@ public class UserManager {
|
|||||||
REMOVE_RESULT_REMOVED,
|
REMOVE_RESULT_REMOVED,
|
||||||
REMOVE_RESULT_DEFERRED,
|
REMOVE_RESULT_DEFERRED,
|
||||||
REMOVE_RESULT_ALREADY_BEING_REMOVED,
|
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)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
public @interface RemoveResult {}
|
public @interface RemoveResult {}
|
||||||
@@ -4846,8 +4877,10 @@ public class UserManager {
|
|||||||
* the {@link #DISALLOW_REMOVE_USER} or {@link #DISALLOW_REMOVE_MANAGED_PROFILE} restriction
|
* the {@link #DISALLOW_REMOVE_USER} or {@link #DISALLOW_REMOVE_MANAGED_PROFILE} restriction
|
||||||
*
|
*
|
||||||
* @return the {@link RemoveResult} code: {@link #REMOVE_RESULT_REMOVED},
|
* @return the {@link RemoveResult} code: {@link #REMOVE_RESULT_REMOVED},
|
||||||
* {@link #REMOVE_RESULT_DEFERRED}, {@link #REMOVE_RESULT_ALREADY_BEING_REMOVED}, or
|
* {@link #REMOVE_RESULT_DEFERRED}, {@link #REMOVE_RESULT_ALREADY_BEING_REMOVED},
|
||||||
* {@link #REMOVE_RESULT_ERROR}.
|
* {@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
|
* @hide
|
||||||
*/
|
*/
|
||||||
@@ -4863,6 +4896,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.
|
* Updates the user's name.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ public class MasterClearReceiver extends BroadcastReceiver {
|
|||||||
final UserManager userManager = context.getSystemService(UserManager.class);
|
final UserManager userManager = context.getSystemService(UserManager.class);
|
||||||
final int result = userManager.removeUserWhenPossible(
|
final int result = userManager.removeUserWhenPossible(
|
||||||
UserHandle.of(userId), /* overrideDevicePolicy= */ false);
|
UserHandle.of(userId), /* overrideDevicePolicy= */ false);
|
||||||
if (result == UserManager.REMOVE_RESULT_ERROR) {
|
if (!UserManager.isRemoveResultSuccessful(result)) {
|
||||||
Slogf.e(TAG, "Can't remove user %d", userId);
|
Slogf.e(TAG, "Can't remove user %d", userId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4638,12 +4638,12 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
final String restriction = getUserRemovalRestriction(userId);
|
final String restriction = getUserRemovalRestriction(userId);
|
||||||
if (getUserRestrictions(UserHandle.getCallingUserId()).getBoolean(restriction, false)) {
|
if (getUserRestrictions(UserHandle.getCallingUserId()).getBoolean(restriction, false)) {
|
||||||
Slog.w(LOG_TAG, "Cannot remove user. " + restriction + " is enabled.");
|
Slog.w(LOG_TAG, "Cannot remove user. " + restriction + " is enabled.");
|
||||||
return UserManager.REMOVE_RESULT_ERROR;
|
return UserManager.REMOVE_RESULT_ERROR_USER_RESTRICTION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (userId == UserHandle.USER_SYSTEM) {
|
if (userId == UserHandle.USER_SYSTEM) {
|
||||||
Slog.e(LOG_TAG, "System user cannot be removed.");
|
Slog.e(LOG_TAG, "System user cannot be removed.");
|
||||||
return UserManager.REMOVE_RESULT_ERROR;
|
return UserManager.REMOVE_RESULT_ERROR_SYSTEM_USER;
|
||||||
}
|
}
|
||||||
|
|
||||||
final long ident = Binder.clearCallingIdentity();
|
final long ident = Binder.clearCallingIdentity();
|
||||||
@@ -4655,7 +4655,7 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
if (userData == null) {
|
if (userData == null) {
|
||||||
Slog.e(LOG_TAG,
|
Slog.e(LOG_TAG,
|
||||||
"Cannot remove user " + userId + ", invalid user id provided.");
|
"Cannot remove user " + userId + ", invalid user id provided.");
|
||||||
return UserManager.REMOVE_RESULT_ERROR;
|
return UserManager.REMOVE_RESULT_ERROR_USER_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mRemovingUserIds.get(userId)) {
|
if (mRemovingUserIds.get(userId)) {
|
||||||
|
|||||||
@@ -316,7 +316,8 @@ public final class UserManagerTest {
|
|||||||
asHandle(currentUser));
|
asHandle(currentUser));
|
||||||
try {
|
try {
|
||||||
assertThat(mUserManager.removeUserWhenPossible(user1.getUserHandle(),
|
assertThat(mUserManager.removeUserWhenPossible(user1.getUserHandle(),
|
||||||
/* overrideDevicePolicy= */ false)).isEqualTo(UserManager.REMOVE_RESULT_ERROR);
|
/* overrideDevicePolicy= */ false))
|
||||||
|
.isEqualTo(UserManager.REMOVE_RESULT_ERROR_USER_RESTRICTION);
|
||||||
} finally {
|
} finally {
|
||||||
mUserManager.setUserRestriction(UserManager.DISALLOW_REMOVE_USER, /* value= */ false,
|
mUserManager.setUserRestriction(UserManager.DISALLOW_REMOVE_USER, /* value= */ false,
|
||||||
asHandle(currentUser));
|
asHandle(currentUser));
|
||||||
@@ -353,7 +354,8 @@ public final class UserManagerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testRemoveUserWhenPossible_systemUserReturnsError() throws Exception {
|
public void testRemoveUserWhenPossible_systemUserReturnsError() throws Exception {
|
||||||
assertThat(mUserManager.removeUserWhenPossible(UserHandle.SYSTEM,
|
assertThat(mUserManager.removeUserWhenPossible(UserHandle.SYSTEM,
|
||||||
/* overrideDevicePolicy= */ false)).isEqualTo(UserManager.REMOVE_RESULT_ERROR);
|
/* overrideDevicePolicy= */ false))
|
||||||
|
.isEqualTo(UserManager.REMOVE_RESULT_ERROR_SYSTEM_USER);
|
||||||
|
|
||||||
assertThat(hasUser(UserHandle.USER_SYSTEM)).isTrue();
|
assertThat(hasUser(UserHandle.USER_SYSTEM)).isTrue();
|
||||||
}
|
}
|
||||||
@@ -363,7 +365,8 @@ public final class UserManagerTest {
|
|||||||
public void testRemoveUserWhenPossible_invalidUserReturnsError() throws Exception {
|
public void testRemoveUserWhenPossible_invalidUserReturnsError() throws Exception {
|
||||||
assertThat(hasUser(Integer.MAX_VALUE)).isFalse();
|
assertThat(hasUser(Integer.MAX_VALUE)).isFalse();
|
||||||
assertThat(mUserManager.removeUserWhenPossible(UserHandle.of(Integer.MAX_VALUE),
|
assertThat(mUserManager.removeUserWhenPossible(UserHandle.of(Integer.MAX_VALUE),
|
||||||
/* overrideDevicePolicy= */ false)).isEqualTo(UserManager.REMOVE_RESULT_ERROR);
|
/* overrideDevicePolicy= */ false))
|
||||||
|
.isEqualTo(UserManager.REMOVE_RESULT_ERROR_USER_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@MediumTest
|
@MediumTest
|
||||||
|
|||||||
Reference in New Issue
Block a user