diff options
author | 2025-02-20 12:10:40 -0800 | |
---|---|---|
committer | 2025-02-20 14:18:20 -0800 | |
commit | 4bb35668c0f5c232a5fe8c9393cd6eac8132023d (patch) | |
tree | a2a2c3a7c3aa4c5fe5e1cc5b9a3ac33983cef41c | |
parent | 7ff8eff7146e1a313f9783f7a1b005c0da8a0c7c (diff) |
Allow bypassing qualification to work properly with static roles
Right now bypassing qualification for a static role allows assigning a
different holder initially but still randomly reverts it later on. We
should not try to revert to the static holder while we are bypassing
qualifications.
Bug: 390304109
Flag: EXEMPT bugfix
Test: presubmit
Relnote: N/A
Change-Id: I64881c83798cd32f7766eab5f9b609f4bdbb4dee
2 files changed, 16 insertions, 6 deletions
diff --git a/PermissionController/role-controller/java/com/android/role/controller/model/Role.java b/PermissionController/role-controller/java/com/android/role/controller/model/Role.java index 32910c69d..6a7251563 100644 --- a/PermissionController/role-controller/java/com/android/role/controller/model/Role.java +++ b/PermissionController/role-controller/java/com/android/role/controller/model/Role.java @@ -504,8 +504,14 @@ public class Role { && Build.VERSION.SDK_INT <= mMaxSdkVersion; } - public boolean isStatic() { - return mStatic; + /** + * Check whether this role is static, which may change due to bypassing qualification. + * + * @param context the {@code Context} to retrieve system services + * @return whether this role is static + */ + public boolean isStatic(@NonNull Context context) { + return mStatic && !isBypassingQualification(context); } /** @@ -620,6 +626,12 @@ public class Role { return mAllowBypassingQualification; } + private boolean isBypassingQualification(@NonNull Context context) { + RoleManager roleManager = context.getSystemService(RoleManager.class); + return shouldAllowBypassingQualification(context) + && RoleManagerCompat.isBypassingRoleQualification(roleManager); + } + /** * Check whether a package is qualified for this role, i.e. whether it contains all the required * components (plus meeting some other general restrictions). @@ -632,9 +644,7 @@ public class Role { */ public boolean isPackageQualifiedAsUser(@NonNull String packageName, @NonNull UserHandle user, @NonNull Context context) { - RoleManager roleManager = context.getSystemService(RoleManager.class); - if (shouldAllowBypassingQualification(context) - && RoleManagerCompat.isBypassingRoleQualification(roleManager)) { + if (isBypassingQualification(context)) { return true; } diff --git a/PermissionController/role-controller/java/com/android/role/controller/service/RoleControllerServiceImpl.java b/PermissionController/role-controller/java/com/android/role/controller/service/RoleControllerServiceImpl.java index d00fd47af..1a0c83ab8 100644 --- a/PermissionController/role-controller/java/com/android/role/controller/service/RoleControllerServiceImpl.java +++ b/PermissionController/role-controller/java/com/android/role/controller/service/RoleControllerServiceImpl.java @@ -173,7 +173,7 @@ public class RoleControllerServiceImpl extends RoleControllerService { // or fallback holders, if any. currentPackageNames = mUserRoleManager.getRoleHolders(roleName); currentPackageNamesSize = currentPackageNames.size(); - boolean isStaticRole = role.isStatic(); + boolean isStaticRole = role.isStatic(mContext); if (currentPackageNamesSize == 0 || isStaticRole) { List<String> packageNamesToAdd = null; if (addedRoleNames.contains(roleName) || isStaticRole) { |