Return null when getting role holders of an unknown role.
Previously the code was accidentally relying on ArraySet constructor
accepting a null argument when the role is not found, so make it
return null in this case to match both the javadoc and what we
intended.
Bug: 110557011
Test: build
Change-Id: Ifef270a84854c105d9627ee15e96a649dfac0abf
diff --git a/services/core/java/com/android/server/role/RoleUserState.java b/services/core/java/com/android/server/role/RoleUserState.java
index 69e1449..02dcc49 100644
--- a/services/core/java/com/android/server/role/RoleUserState.java
+++ b/services/core/java/com/android/server/role/RoleUserState.java
@@ -193,14 +193,18 @@
*
* @param roleName the name of the role to query for
*
- * @return the set of role holders. {@code null} should not be returned and indicates an issue.
+ * @return the set of role holders, or {@code null} if and only if the role is not found
*/
@Nullable
public ArraySet<String> getRoleHolders(@NonNull String roleName) {
synchronized (mLock) {
throwIfDestroyedLocked();
- return new ArraySet<>(mRoles.get(roleName));
+ ArraySet<String> packageNames = mRoles.get(roleName);
+ if (packageNames == null) {
+ return null;
+ }
+ return new ArraySet<>(packageNames);
}
}
@@ -268,8 +272,7 @@
* @param roleName the name of the role to add the holder to
* @param packageName the package name of the new holder
*
- * @return {@code false} only if the set of role holders is null, which should not happen and
- * indicates an issue.
+ * @return {@code false} if and only if the role is not found
*/
@CheckResult
public boolean addRoleHolder(@NonNull String roleName, @NonNull String packageName) {
@@ -302,8 +305,7 @@
* @param roleName the name of the role to remove the holder from
* @param packageName the package name of the holder to remove
*
- * @return {@code false} only if the set of role holders is null, which should not happen and
- * indicates an issue.
+ * @return {@code false} if and only if the role is not found
*/
@CheckResult
public boolean removeRoleHolder(@NonNull String roleName, @NonNull String packageName) {