From 787ec3d945b1557225c76a998f2b16d72104a789 Mon Sep 17 00:00:00 2001 From: Richard MacGregor Date: Fri, 17 Jan 2025 17:53:13 -0800 Subject: Show profilegroup exclusive roles in defaultapps Fix bug where default apps list opened using work profile context wouldn't show profilegroup exclusive roles when full-user is set as active user LOW_COVERAGE_REASON=FLAG_NOT_ENABLED Bug: 385424712 Flag: com.android.permission.flags.cross_user_role_ux_bugfix_enabled Relnote: N/A Test: atest RoleManagerMultiUserTest Change-Id: I35bb290179432ff44b60bcab53cdf0952aa7573c --- .../role/ui/DefaultAppListViewModel.java | 22 +++++++++++++++++++--- .../permissioncontroller/role/utils/UserUtils.java | 13 ------------- 2 files changed, 19 insertions(+), 16 deletions(-) (limited to 'PermissionController/src') diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/DefaultAppListViewModel.java b/PermissionController/src/com/android/permissioncontroller/role/ui/DefaultAppListViewModel.java index e4a3cbc17..718af090e 100644 --- a/PermissionController/src/com/android/permissioncontroller/role/ui/DefaultAppListViewModel.java +++ b/PermissionController/src/com/android/permissioncontroller/role/ui/DefaultAppListViewModel.java @@ -28,12 +28,14 @@ import androidx.lifecycle.LiveData; import androidx.lifecycle.Transformations; import androidx.lifecycle.ViewModel; +import com.android.permission.flags.Flags; import com.android.permissioncontroller.permission.utils.Utils; import com.android.permissioncontroller.role.utils.UserUtils; import com.android.role.controller.model.Role; import com.android.role.controller.util.RoleFlags; import java.util.List; +import java.util.Objects; import java.util.function.Predicate; /** @@ -58,18 +60,21 @@ public class DefaultAppListViewModel extends AndroidViewModel { super(application); mUser = Process.myUserHandle(); - boolean isProfileParent = UserUtils.isProfileParent(mUser, application); + UserHandle profileParent = UserUtils.getProfileParentOrSelf(mUser, application); + UserHandle workProfile = UserUtils.getWorkProfileOrSelf(application); + boolean isProfileParent = Objects.equals(mUser, profileParent); + boolean isWorkProfile = Objects.equals(mUser, workProfile); RoleListLiveData liveData = new RoleListLiveData(true, mUser, application); RoleListSortFunction sortFunction = new RoleListSortFunction(application); // Only show the work profile section if the current user is a full user mWorkProfile = isProfileParent ? UserUtils.getWorkProfile(application) : null; if (RoleFlags.isProfileGroupExclusivityAvailable()) { + Predicate exclusivityPredicate = roleItem -> + roleItem.getRole().getExclusivity() == Role.EXCLUSIVITY_PROFILE_GROUP; if (mWorkProfile != null) { // Show profile group exclusive roles from work profile in primary group. RoleListLiveData workLiveData = new RoleListLiveData(true, mWorkProfile, application); - Predicate exclusivityPredicate = roleItem -> - roleItem.getRole().getExclusivity() == Role.EXCLUSIVITY_PROFILE_GROUP; mLiveData = Transformations.map( new MergeRoleListLiveData(liveData, Transformations.map(workLiveData, @@ -79,6 +84,17 @@ public class DefaultAppListViewModel extends AndroidViewModel { Transformations.map(workLiveData, new RoleListFilterFunction(exclusivityPredicate.negate())), sortFunction); + } else if (Flags.crossUserRoleUxBugfixEnabled() && isWorkProfile) { + // Show profile group exclusive roles from the profile parent (full user) in primary + // group when the current user (primary group) is a work profile + RoleListLiveData profileParentLiveData = + new RoleListLiveData(true, profileParent, application); + mLiveData = Transformations.map( + new MergeRoleListLiveData(liveData, + Transformations.map(profileParentLiveData, + new RoleListFilterFunction(exclusivityPredicate))), + sortFunction); + mWorkLiveData = null; } else { mLiveData = Transformations.map(liveData, sortFunction); mWorkLiveData = null; diff --git a/PermissionController/src/com/android/permissioncontroller/role/utils/UserUtils.java b/PermissionController/src/com/android/permissioncontroller/role/utils/UserUtils.java index f03c31bd8..4d778befb 100644 --- a/PermissionController/src/com/android/permissioncontroller/role/utils/UserUtils.java +++ b/PermissionController/src/com/android/permissioncontroller/role/utils/UserUtils.java @@ -131,19 +131,6 @@ public class UserUtils { return null; } - /** - * Returns whether the user is a parent/full-user or not. - * - * @param userHandle the {@code UserHandle} to check is private profile - * @param context the {@code Context} to retrieve system services - */ - public static boolean isProfileParent(@NonNull UserHandle userHandle, - @NonNull Context context) { - // If profile parent user is null, then original user is the parent - return com.android.role.controller.util.UserUtils.getProfileParent(userHandle, context) - == null; - } - /** * Returns whether the user is a private profile or not. * -- cgit v1.2.3-59-g8ed1b