diff options
Diffstat (limited to 'PermissionController/role-controller/java')
-rw-r--r-- | PermissionController/role-controller/java/com/android/role/controller/behavior/ReservedForTestingProfileGroupExclusivityRoleBehavior.java | 31 |
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; + } + } } |