summaryrefslogtreecommitdiff
path: root/PermissionController/role-controller/java
diff options
context:
space:
mode:
author Richard MacGregor <rmacgregor@google.com> 2024-12-05 16:49:02 -0800
committer Richard MacGregor <rmacgregor@google.com> 2024-12-11 12:22:06 -0800
commite0d6985188ceb5dc60e5ac46d66e71fb4888bb24 (patch)
tree225d9eb5dc5c254b33f42d624587054175d9d073 /PermissionController/role-controller/java
parentd63f781a4236f33f7737624005ff5e570371a4d7 (diff)
Profile group exclusive roles setting changes
Show profile group exclusive roles in primary default app list section. Show all users for which profile group exclusive role is available in default app screen. LOW_COVERAGE_REASON=FLAG_NOT_ENABLED Relnote: N/A Flag: com.android.permission.flags.cross_user_role_enabled Bug: 378887269 Test: atest RoleManagerTest Test: atest RoleManagerMultiUserTest Change-Id: Id0596f089d8cdcf13941646c547871fce679de18
Diffstat (limited to 'PermissionController/role-controller/java')
-rw-r--r--PermissionController/role-controller/java/com/android/role/controller/behavior/ReservedForTestingProfileGroupExclusivityRoleBehavior.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/PermissionController/role-controller/java/com/android/role/controller/behavior/ReservedForTestingProfileGroupExclusivityRoleBehavior.java b/PermissionController/role-controller/java/com/android/role/controller/behavior/ReservedForTestingProfileGroupExclusivityRoleBehavior.java
index 91b4e1531..f02b4d90c 100644
--- a/PermissionController/role-controller/java/com/android/role/controller/behavior/ReservedForTestingProfileGroupExclusivityRoleBehavior.java
+++ b/PermissionController/role-controller/java/com/android/role/controller/behavior/ReservedForTestingProfileGroupExclusivityRoleBehavior.java
@@ -18,6 +18,7 @@ package com.android.role.controller.behavior;
import android.app.role.RoleManager;
import android.content.Context;
+import android.content.pm.ApplicationInfo;
import android.os.UserHandle;
import androidx.annotation.NonNull;
@@ -25,11 +26,14 @@ import androidx.annotation.Nullable;
import com.android.role.controller.model.Role;
import com.android.role.controller.model.RoleBehavior;
+import com.android.role.controller.util.PackageUtils;
import com.android.role.controller.util.RoleFlags;
import com.android.role.controller.util.UserUtils;
+import java.util.ArrayList;
import java.util.List;
+// TODO(b/383538899): make minSdk36
public class ReservedForTestingProfileGroupExclusivityRoleBehavior implements RoleBehavior {
@Nullable
@Override
@@ -55,4 +59,31 @@ public class ReservedForTestingProfileGroupExclusivityRoleBehavior implements Ro
return false;
}
}
+
+ @Nullable
+ @Override
+ public List<String> getQualifyingPackagesAsUser(@NonNull Role role, @NonNull UserHandle user,
+ @NonNull Context context) {
+ if (RoleFlags.isProfileGroupExclusivityAvailable()) {
+ Context userContext = UserUtils.getUserContext(context, user);
+ RoleManager userRoleManager = userContext.getSystemService(RoleManager.class);
+ List<String> qualifyingPackageNames =
+ userRoleManager.getDefaultHoldersForTest(role.getName());
+
+ // When getQualifyingPackagesAsUser returns a package that isn't installed, Default App
+ // Settings fails to load. Only return available packages.
+ List<String> availableQualifyingPackageNames = new ArrayList<>();
+ for (int i = 0; i < qualifyingPackageNames.size(); i++) {
+ String qualifyingPackage = qualifyingPackageNames.get(i);
+ ApplicationInfo applicationInfo =
+ PackageUtils.getApplicationInfoAsUser(qualifyingPackage, user, context);
+ if (applicationInfo != null) {
+ availableQualifyingPackageNames.add(qualifyingPackage);
+ }
+ }
+ return availableQualifyingPackageNames;
+ } else {
+ return null;
+ }
+ }
}