diff options
author | 2024-12-02 17:49:31 -0800 | |
---|---|---|
committer | 2024-12-05 11:29:41 -0800 | |
commit | 769838e9a9d864bc64fd88a2c8bdd47e1b90007b (patch) | |
tree | 59ed7852b705285c9a40a7e7b118bd7ab5757d13 /framework-s/java | |
parent | 0cdf86d86a3f10cf22d4c3a440f949dba0993a1f (diff) |
Add get/setDefaultHoldersForTest and is/setRoleVisibleForTest
Add role methods to assist in setting test role visiblity and default holders
LOW_COVERAGE_REASON=b/382484309
Relnote: N/A
Flag: com.android.permission.flags.cross_user_role_enabled
Bug: 381315745
Test: atest RoleManagerTest
Change-Id: I6d1d4200849a2be994f83da675fc57837ae7204f
Diffstat (limited to 'framework-s/java')
-rw-r--r-- | framework-s/java/android/app/role/IRoleManager.aidl | 8 | ||||
-rw-r--r-- | framework-s/java/android/app/role/RoleManager.java | 112 |
2 files changed, 120 insertions, 0 deletions
diff --git a/framework-s/java/android/app/role/IRoleManager.aidl b/framework-s/java/android/app/role/IRoleManager.aidl index cd0079e08..dc5bc8cb4 100644 --- a/framework-s/java/android/app/role/IRoleManager.aidl +++ b/framework-s/java/android/app/role/IRoleManager.aidl @@ -84,4 +84,12 @@ interface IRoleManager { boolean isApplicationVisibleForRoleAsUser(in String roleName, in String packageName, int userId); + + List<String> getDefaultHoldersForTest(in String roleName); + + void setDefaultHoldersForTest(in String roleName, in List<String> packageNames); + + boolean isRoleVisibleForTest(in String roleName); + + void setRoleVisibleForTest(in String roleName, boolean visible); } diff --git a/framework-s/java/android/app/role/RoleManager.java b/framework-s/java/android/app/role/RoleManager.java index 6f62fdd76..42445b4d6 100644 --- a/framework-s/java/android/app/role/RoleManager.java +++ b/framework-s/java/android/app/role/RoleManager.java @@ -1166,6 +1166,118 @@ public final class RoleManager { } } + /** + * Get the default holders of this role, which will be added when the role is added for the + * first time. + * <p> + * <strong>Note:</strong> Use of this API should be limited to tests. The values returned are + * not persisted. + * <p> + * Throws {@link IllegalArgumentException} if role is not a test role + * + * @param roleName the name of the role to get test default holders for + * @return the list of package names of the default holders + * + * @hide + */ + @RequiresPermission(Manifest.permission.MANAGE_ROLE_HOLDERS) + @RequiresApi(Build.VERSION_CODES.BAKLAVA) + @SystemApi + @UserHandleAware + @FlaggedApi(com.android.permission.flags.Flags.FLAG_CROSS_USER_ROLE_ENABLED) + @NonNull + public List<String> getDefaultHoldersForTest(@NonNull String roleName) { + Preconditions.checkStringNotEmpty(roleName, "roleName cannot be null or empty"); + try { + return mService.getDefaultHoldersForTest(roleName); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** + * Set the default holders of this role, which will be added when the role is added for the + * first time. + * <p> + * <strong>Note:</strong> Use of this API should be limited to tests. The values used are + * not persisted. + * <p> + * Throws {@link IllegalArgumentException} if role is not a test role + * + * @param roleName the name of the role to set test default holders for + * @param packageNames a list of package names of the default holders or {@code null} to unset + * + * @hide + */ + @RequiresPermission(Manifest.permission.MANAGE_ROLE_HOLDERS) + @RequiresApi(Build.VERSION_CODES.BAKLAVA) + @SystemApi + @UserHandleAware + @FlaggedApi(com.android.permission.flags.Flags.FLAG_CROSS_USER_ROLE_ENABLED) + public void setDefaultHoldersForTest( + @NonNull String roleName, @Nullable List<String> packageNames) { + Preconditions.checkStringNotEmpty(roleName, "roleName cannot be null or empty"); + try { + mService.setDefaultHoldersForTest(roleName, packageNames); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** + * Get whether a role should be visible for testing. + * <p> + * <strong>Note:</strong> Use of this API should be limited to tests. The values returned are + * not persisted. + * <p> + * Throws {@link IllegalArgumentException} if role is not a test role + * + * @param roleName the name of the role to get test visibility for + * @return {@code true} if role is visible, {@code false} otherwise + * + * @hide + */ + @RequiresPermission(Manifest.permission.MANAGE_ROLE_HOLDERS) + @RequiresApi(Build.VERSION_CODES.BAKLAVA) + @SystemApi + @UserHandleAware + @FlaggedApi(com.android.permission.flags.Flags.FLAG_CROSS_USER_ROLE_ENABLED) + public boolean isRoleVisibleForTest(@NonNull String roleName) { + Preconditions.checkStringNotEmpty(roleName, "roleName cannot be null or empty"); + try { + return mService.isRoleVisibleForTest(roleName); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** + * Set whether a role should be visible for testing. + * <p> + * <strong>Note:</strong> Use of this API should be limited to tests. The values used are + * not persisted. + * <p> + * Throws {@link IllegalArgumentException} if role is not a test role + * + * @param roleName the name of the role to set test visibility for + * @param visible {@code true} to set role as visible, {@code false} otherwise + * + * @hide + */ + @RequiresPermission(Manifest.permission.MANAGE_ROLE_HOLDERS) + @RequiresApi(Build.VERSION_CODES.BAKLAVA) + @SystemApi + @UserHandleAware + @FlaggedApi(com.android.permission.flags.Flags.FLAG_CROSS_USER_ROLE_ENABLED) + public void setRoleVisibleForTest(@NonNull String roleName, boolean visible) { + Preconditions.checkStringNotEmpty(roleName, "roleName cannot be null or empty"); + try { + mService.setRoleVisibleForTest(roleName, visible); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + @NonNull private RoleControllerManager getRoleControllerManager() { synchronized (mRoleControllerManagerLock) { |