summaryrefslogtreecommitdiff
path: root/service/java/com
diff options
context:
space:
mode:
author Richard MacGregor <rmacgregor@google.com> 2024-12-02 15:51:37 -0800
committer Richard MacGregor <rmacgregor@google.com> 2024-12-19 08:30:21 -0800
commit6546139431994bba3b96c2fe45f7771d1684cef7 (patch)
tree513a28b1d405ca9fec238a3520ea7efb3bf163fb /service/java/com
parent741b2ca214ca04b3fe9e6b91fe5363f7205cfccc (diff)
Set full user as active if active user removed
On removal of a user, set it's parent user as active for all roles in which the removed user was marked as active LOW_COVERAGE_REASON=FLAG_NOT_ENABLED Relnote: N/A Flag: com.android.permission.flags.cross_user_role_enabled Bug: 375029649 Test: atest RoleManagerMultiUserTest Change-Id: If8dc5b1d74e7d37a8758d31470a5b91a1294428a
Diffstat (limited to 'service/java/com')
-rw-r--r--service/java/com/android/role/RoleService.java26
-rw-r--r--service/java/com/android/role/RoleUserState.java16
2 files changed, 41 insertions, 1 deletions
diff --git a/service/java/com/android/role/RoleService.java b/service/java/com/android/role/RoleService.java
index deb0cf3b0..5bc79efbb 100644
--- a/service/java/com/android/role/RoleService.java
+++ b/service/java/com/android/role/RoleService.java
@@ -219,7 +219,6 @@ public class RoleService extends SystemService implements RoleUserState.Callback
}, intentFilter, null, null);
}
- // TODO(b/375029649): enforce single active user for all cross-user roles
@Override
public void onStart() {
publishBinderService(Context.ROLE_SERVICE, new Stub());
@@ -440,6 +439,9 @@ public class RoleService extends SystemService implements RoleUserState.Callback
private void onRemoveUser(@UserIdInt int userId) {
RemoteCallbackList<IOnRoleHoldersChangedListener> listeners;
RoleUserState userState;
+ // UserManager still knows the user until ACTION_USER_REMOVED broadcasts are processed
+ int profileParentId = UserUtils.getProfileParentIdOrSelf(userId, getContext());
+ List<String> activeRoleNames = null;
synchronized (mLock) {
mGrantDefaultRolesThrottledRunnables.remove(userId);
listeners = mListeners.get(userId);
@@ -447,7 +449,29 @@ public class RoleService extends SystemService implements RoleUserState.Callback
mControllers.remove(userId);
userState = mUserStates.get(userId);
mUserStates.remove(userId);
+
+ if (RoleFlags.isProfileGroupExclusivityAvailable() && userId != profileParentId) {
+ RoleUserState profileParentState = mUserStates.get(profileParentId);
+ activeRoleNames = profileParentState.getActiveRolesForUser(userId);
+ }
}
+ if (RoleFlags.isProfileGroupExclusivityAvailable() && userId != profileParentId
+ && !CollectionUtils.isEmpty(activeRoleNames)) {
+ int activeRoleNamesSize = activeRoleNames.size();
+ for (int i = 0; i < activeRoleNamesSize; i++) {
+ String roleName = activeRoleNames.get(i);
+
+ // If the previous active user had a set role holder, attempt to fallback for
+ // the profile parent.
+ Log.i(LOG_TAG, "User " + userId + " removed, falling back to profile parent "
+ + profileParentId + " for role " + roleName);
+ // Use profileParentId instead of userId here, since userId is in a state of removal
+ // and might be excluded from UserManager#getUserHandles with excludeDying=true
+ setActiveUserForRoleAsUserInternal(roleName, profileParentId, 0, true,
+ profileParentId);
+ }
+ }
+
if (listeners != null) {
listeners.kill();
}
diff --git a/service/java/com/android/role/RoleUserState.java b/service/java/com/android/role/RoleUserState.java
index 7f59f1385..18574a6fc 100644
--- a/service/java/com/android/role/RoleUserState.java
+++ b/service/java/com/android/role/RoleUserState.java
@@ -447,6 +447,22 @@ class RoleUserState {
}
}
+ @NonNull
+ public List<String> getActiveRolesForUser(@UserIdInt int userId) {
+ synchronized (mLock) {
+ List<String> activeRoleNames = new ArrayList<>();
+ int activeUserIdsSize = mActiveUserIds.size();
+ for (int i = 0; i < activeUserIdsSize; i++) {
+ int activeUserId = mActiveUserIds.valueAt(i);
+ if (activeUserId == userId) {
+ String roleName = mActiveUserIds.keyAt(i);
+ activeRoleNames.add(roleName);
+ }
+ }
+ return activeRoleNames;
+ }
+ }
+
/**
* Set the active user for the role
*