From 59675001a55932c51c97d61e303ed2233d5fcb33 Mon Sep 17 00:00:00 2001 From: Richard MacGregor Date: Thu, 23 Jan 2025 14:51:14 -0800 Subject: Add missing preconditions to get/setDefaultApplicationAsUser Add missing preconditions to ensure these methods are not called on APIs lower than U Bug: 379362792 Flag: EXEMPT bug fix Relnote: Fix API preconditions Test: atest RoleManagerSecurityTest Change-Id: Iadc97d09cf083e2525de421362c5a4bece92ee8a --- service/java/com/android/role/RoleService.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'service/java') diff --git a/service/java/com/android/role/RoleService.java b/service/java/com/android/role/RoleService.java index 5bc79efbb..6b44c4c05 100644 --- a/service/java/com/android/role/RoleService.java +++ b/service/java/com/android/role/RoleService.java @@ -733,6 +733,9 @@ public class RoleService extends SystemService implements RoleUserState.Callback @Override @Nullable public String getDefaultApplicationAsUser(@NonNull String roleName, @UserIdInt int userId) { + // The MANAGE_DEFAULT_APPLICATIONS permission is only available on U+ + Preconditions.checkState(SdkLevel.isAtLeastU(), + "This API is only available on Android 34 and above"); UserUtils.enforceCrossUserPermission(userId, /* allowAll= */ false, /* enforceForProfileGroup= */ false, "getDefaultApplicationAsUser", getContext()); @@ -759,6 +762,9 @@ public class RoleService extends SystemService implements RoleUserState.Callback public void setDefaultApplicationAsUser(@NonNull String roleName, @Nullable String packageName, @RoleManager.ManageHoldersFlags int flags, @UserIdInt int userId, @NonNull RemoteCallback callback) { + // The MANAGE_DEFAULT_APPLICATIONS permission is only available on U+ + Preconditions.checkState(SdkLevel.isAtLeastU(), + "This API is only available on Android 34 and above"); boolean enforceForProfileGroup = isProfileGroupExclusiveRole(roleName, getContext()); UserUtils.enforceCrossUserPermission(userId, /* allowAll= */ false, enforceForProfileGroup, "setDefaultApplicationAsUser", getContext()); -- cgit v1.2.3-59-g8ed1b