summaryrefslogtreecommitdiff
path: root/PermissionController/src
diff options
context:
space:
mode:
author Richard MacGregor <rmacgregor@google.com> 2025-01-24 13:38:09 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2025-01-24 13:38:09 -0800
commit79292285e688378a80ad8f91e4b24d53b5c581fc (patch)
treee963c652a2313c7eae0b071125073662bfa49bc1 /PermissionController/src
parent66629ff4c8ff3e12ae01212f7f93fbee1ba91f85 (diff)
parent787ec3d945b1557225c76a998f2b16d72104a789 (diff)
Merge "Show profilegroup exclusive roles in defaultapps" into main
Diffstat (limited to 'PermissionController/src')
-rw-r--r--PermissionController/src/com/android/permissioncontroller/role/ui/DefaultAppListViewModel.java22
-rw-r--r--PermissionController/src/com/android/permissioncontroller/role/utils/UserUtils.java13
2 files changed, 19 insertions, 16 deletions
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<RoleItem> 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<RoleItem> 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
@@ -132,19 +132,6 @@ public class UserUtils {
}
/**
- * 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.
*
* @param userHandle the {@code UserHandle} to check is private profile