From 4db1b9c12508ff73dbfd4cb0a9dc126cc50ea54d Mon Sep 17 00:00:00 2001 From: Adam Bookatz Date: Thu, 3 Nov 2022 15:50:52 -0700 Subject: [PATCH] UserTypeFactory configurable setMaxAllowed We provide support in config_user_types.xml to change the max number of users allowed of a given user type. This could, e.g., allow multiple Guest users. Note that even though it can be configured, that doesn't mean it'll work - to have more than one Guest user additional work in UMS and other places would be required. Test: atest UserManagerServiceUserTypeTest Bug: 256690588 Change-Id: I02b212bb9a046bbf5662fea05d833f1717e23327 --- core/res/res/xml/config_user_types.xml | 2 ++ services/core/java/com/android/server/pm/UserTypeFactory.java | 1 + services/tests/servicestests/res/xml/usertypes_test_full.xml | 3 ++- .../com/android/server/pm/UserManagerServiceUserTypeTest.java | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/core/res/res/xml/config_user_types.xml b/core/res/res/xml/config_user_types.xml index 766315029f3d1..df6b7b240b389 100644 --- a/core/res/res/xml/config_user_types.xml +++ b/core/res/res/xml/config_user_types.xml @@ -83,6 +83,8 @@ Supported optional properties (to be used as shown in the example above) are as For profile and full users: default-restrictions (with values defined in UserRestrictionUtils.USER_RESTRICTIONS) enabled + user-properties + max-allowed For profile users only: max-allowed-per-parent icon-badge diff --git a/services/core/java/com/android/server/pm/UserTypeFactory.java b/services/core/java/com/android/server/pm/UserTypeFactory.java index b98d20eaa38e6..a73a6e07c689a 100644 --- a/services/core/java/com/android/server/pm/UserTypeFactory.java +++ b/services/core/java/com/android/server/pm/UserTypeFactory.java @@ -388,6 +388,7 @@ public final class UserTypeFactory { } setIntAttribute(parser, "enabled", builder::setEnabled); + setIntAttribute(parser, "max-allowed", builder::setMaxAllowed); // Process child elements. final int depth = parser.getDepth(); diff --git a/services/tests/servicestests/res/xml/usertypes_test_full.xml b/services/tests/servicestests/res/xml/usertypes_test_full.xml index 099ccbe5b5f60..95681434f1938 100644 --- a/services/tests/servicestests/res/xml/usertypes_test_full.xml +++ b/services/tests/servicestests/res/xml/usertypes_test_full.xml @@ -16,7 +16,8 @@ + max-allowed-per-parent='12' + max-allowed='17' > diff --git a/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserTypeTest.java b/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserTypeTest.java index 5f480044d44b1..4ac591284eb1e 100644 --- a/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserTypeTest.java +++ b/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserTypeTest.java @@ -347,6 +347,7 @@ public class UserManagerServiceUserTypeTest { UserTypeDetails details = builders.get(userTypeFull).createUserTypeDetails(); assertEquals(UNLIMITED_NUMBER_OF_USERS, details.getMaxAllowedPerParent()); assertFalse(details.isEnabled()); + assertEquals(17, details.getMaxAllowed()); assertTrue(UserRestrictionsUtils.areEqual( makeRestrictionsBundle("no_remove_user", "no_bluetooth"), details.getDefaultRestrictions()));