Loading core/java/android/content/pm/UserProperties.java +81 −2 Original line number Diff line number Diff line Loading @@ -44,12 +44,14 @@ public final class UserProperties implements Parcelable { private static final String ATTR_SHOW_IN_LAUNCHER = "showInLauncher"; private static final String ATTR_START_WITH_PARENT = "startWithParent"; private static final String ATTR_SHOW_IN_SETTINGS = "showInSettings"; private static final String ATTR_INHERIT_DEVICE_POLICY = "inheritDevicePolicy"; /** Index values of each property (to indicate whether they are present in this object). */ @IntDef(prefix = "INDEX_", value = { INDEX_SHOW_IN_LAUNCHER, INDEX_START_WITH_PARENT, INDEX_SHOW_IN_SETTINGS, INDEX_INHERIT_DEVICE_POLICY, }) @Retention(RetentionPolicy.SOURCE) private @interface PropertyIndex { Loading @@ -57,6 +59,7 @@ public final class UserProperties implements Parcelable { private static final int INDEX_SHOW_IN_LAUNCHER = 0; private static final int INDEX_START_WITH_PARENT = 1; private static final int INDEX_SHOW_IN_SETTINGS = 2; private static final int INDEX_INHERIT_DEVICE_POLICY = 3; /** A bit set, mapping each PropertyIndex to whether it is present (1) or absent (0). */ private long mPropertiesPresent = 0; Loading Loading @@ -120,6 +123,37 @@ public final class UserProperties implements Parcelable { */ public static final int SHOW_IN_SETTINGS_NO = 2; /** * Possible values for whether (and from whom) to inherit select user restrictions * or device policies. * * @hide */ @IntDef(prefix = "INHERIT_DEVICE_POLICY", value = { INHERIT_DEVICE_POLICY_NO, INHERIT_DEVICE_POLICY_FROM_PARENT, }) @Retention(RetentionPolicy.SOURCE) public @interface InheritDevicePolicy { } /** * Suggests that the given user profile should not inherit user restriction or device policy * from any other user. This is the default value for any new user type. * @hide */ public static final int INHERIT_DEVICE_POLICY_NO = 0; /** * Suggests that the given user profile should inherit select user restrictions or * device policies from its parent profile. * *<p> All the user restrictions and device policies would be not propagated to the profile * with this property value. The {(TODO:b/256978256) @link DevicePolicyEngine} * uses this property to determine and propagate only select ones to the given profile. * * @hide */ public static final int INHERIT_DEVICE_POLICY_FROM_PARENT = 1; /** * Reference to the default user properties for this user's user type. * <li>If non-null, then any absent property will use the default property from here instead. Loading Loading @@ -161,6 +195,7 @@ public final class UserProperties implements Parcelable { if (exposeAllFields) { // Add items that require exposeAllFields to be true (strictest permission level). setStartWithParent(orig.getStartWithParent()); setInheritDevicePolicy(orig.getInheritDevicePolicy()); } if (hasManagePermission) { // Add items that require MANAGE_USERS or stronger. Loading Loading @@ -261,6 +296,27 @@ public final class UserProperties implements Parcelable { } private boolean mStartWithParent; /** * Return whether, and how, select user restrictions or device policies should be inherited * from other user. * * Possible return values include * {@link #INHERIT_DEVICE_POLICY_FROM_PARENT} or {@link #INHERIT_DEVICE_POLICY_NO} * * @hide */ public @InheritDevicePolicy int getInheritDevicePolicy() { if (isPresent(INDEX_INHERIT_DEVICE_POLICY)) return mInheritDevicePolicy; if (mDefaultProperties != null) return mDefaultProperties.mInheritDevicePolicy; throw new SecurityException("You don't have permission to query inheritDevicePolicy"); } /** @hide */ public void setInheritDevicePolicy(@InheritDevicePolicy int val) { this.mInheritDevicePolicy = val; setPresent(INDEX_INHERIT_DEVICE_POLICY); } private @InheritDevicePolicy int mInheritDevicePolicy; @Override public String toString() { // Please print in increasing order of PropertyIndex. Loading @@ -269,6 +325,7 @@ public final class UserProperties implements Parcelable { + ", mShowInLauncher=" + getShowInLauncher() + ", mStartWithParent=" + getStartWithParent() + ", mShowInSettings=" + getShowInSettings() + ", mInheritDevicePolicy=" + getInheritDevicePolicy() + "}"; } Loading @@ -283,6 +340,7 @@ public final class UserProperties implements Parcelable { pw.println(prefix + " mShowInLauncher=" + getShowInLauncher()); pw.println(prefix + " mStartWithParent=" + getStartWithParent()); pw.println(prefix + " mShowInSettings=" + getShowInSettings()); pw.println(prefix + " mInheritDevicePolicy=" + getInheritDevicePolicy()); } /** Loading Loading @@ -324,6 +382,10 @@ public final class UserProperties implements Parcelable { break; case ATTR_SHOW_IN_SETTINGS: setShowInSettings(parser.getAttributeInt(i)); break; case ATTR_INHERIT_DEVICE_POLICY: setInheritDevicePolicy(parser.getAttributeInt(i)); break; default: Slog.w(LOG_TAG, "Skipping unknown property " + attributeName); } Loading @@ -350,6 +412,10 @@ public final class UserProperties implements Parcelable { if (isPresent(INDEX_SHOW_IN_SETTINGS)) { serializer.attributeInt(null, ATTR_SHOW_IN_SETTINGS, mShowInSettings); } if (isPresent(INDEX_INHERIT_DEVICE_POLICY)) { serializer.attributeInt(null, ATTR_INHERIT_DEVICE_POLICY, mInheritDevicePolicy); } } // For use only with an object that has already had any permission-lacking fields stripped out. Loading @@ -359,6 +425,7 @@ public final class UserProperties implements Parcelable { dest.writeInt(mShowInLauncher); dest.writeBoolean(mStartWithParent); dest.writeInt(mShowInSettings); dest.writeInt(mInheritDevicePolicy); } /** Loading @@ -372,6 +439,7 @@ public final class UserProperties implements Parcelable { mShowInLauncher = source.readInt(); mStartWithParent = source.readBoolean(); mShowInSettings = source.readInt(); mInheritDevicePolicy = source.readInt(); } @Override Loading Loading @@ -399,6 +467,7 @@ public final class UserProperties implements Parcelable { private @ShowInLauncher int mShowInLauncher = SHOW_IN_LAUNCHER_WITH_PARENT; private boolean mStartWithParent = false; private @ShowInSettings int mShowInSettings = SHOW_IN_SETTINGS_WITH_PARENT; private @InheritDevicePolicy int mInheritDevicePolicy = INHERIT_DEVICE_POLICY_NO; public Builder setShowInLauncher(@ShowInLauncher int showInLauncher) { mShowInLauncher = showInLauncher; Loading @@ -416,12 +485,20 @@ public final class UserProperties implements Parcelable { return this; } /** Sets the value for {@link #mInheritDevicePolicy}*/ public Builder setInheritDevicePolicy( @InheritDevicePolicy int inheritRestrictionsDevicePolicy) { mInheritDevicePolicy = inheritRestrictionsDevicePolicy; return this; } /** Builds a UserProperties object with *all* values populated. */ public UserProperties build() { return new UserProperties( mShowInLauncher, mStartWithParent, mShowInSettings); mShowInSettings, mInheritDevicePolicy); } } // end Builder Loading @@ -429,11 +506,13 @@ public final class UserProperties implements Parcelable { private UserProperties( @ShowInLauncher int showInLauncher, boolean startWithParent, @ShowInSettings int showInSettings) { @ShowInSettings int showInSettings, @InheritDevicePolicy int inheritDevicePolicy) { mDefaultProperties = null; setShowInLauncher(showInLauncher); setStartWithParent(startWithParent); setShowInSettings(showInSettings); setInheritDevicePolicy(inheritDevicePolicy); } } services/core/java/com/android/server/pm/UserTypeFactory.java +2 −1 Original line number Diff line number Diff line Loading @@ -129,7 +129,8 @@ public final class UserTypeFactory { .setDefaultUserProperties(new UserProperties.Builder() .setStartWithParent(true) .setShowInLauncher(UserProperties.SHOW_IN_LAUNCHER_WITH_PARENT) .setShowInSettings(UserProperties.SHOW_IN_SETTINGS_WITH_PARENT)); .setShowInSettings(UserProperties.SHOW_IN_SETTINGS_WITH_PARENT) .setInheritDevicePolicy(UserProperties.INHERIT_DEVICE_POLICY_FROM_PARENT)); } /** Loading services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserPropertiesTest.java +8 −0 Original line number Diff line number Diff line Loading @@ -60,10 +60,12 @@ public class UserManagerServiceUserPropertiesTest { .setShowInLauncher(21) .setStartWithParent(false) .setShowInSettings(45) .setInheritDevicePolicy(67) .build(); final UserProperties actualProps = new UserProperties(defaultProps); actualProps.setShowInLauncher(14); actualProps.setShowInSettings(32); actualProps.setInheritDevicePolicy(51); // Write the properties to xml. final ByteArrayOutputStream baos = new ByteArrayOutputStream(); Loading Loading @@ -102,11 +104,13 @@ public class UserManagerServiceUserPropertiesTest { .setShowInLauncher(2145) .setStartWithParent(true) .setShowInSettings(3452) .setInheritDevicePolicy(1732) .build(); final UserProperties orig = new UserProperties(defaultProps); orig.setShowInLauncher(2841); orig.setStartWithParent(false); orig.setShowInSettings(1437); orig.setInheritDevicePolicy(9456); // Test every permission level. (Currently, it's linear so it's easy.) for (int permLevel = 0; permLevel < 4; permLevel++) { Loading Loading @@ -142,6 +146,8 @@ public class UserManagerServiceUserPropertiesTest { // Items requiring exposeAll. assertEqualGetterOrThrows(orig::getStartWithParent, copy::getStartWithParent, exposeAll); assertEqualGetterOrThrows(orig::getInheritDevicePolicy, copy::getInheritDevicePolicy, exposeAll); // Items requiring hasManagePermission - put them here using hasManagePermission. assertEqualGetterOrThrows(orig::getShowInSettings, copy::getShowInSettings, Loading Loading @@ -190,5 +196,7 @@ public class UserManagerServiceUserPropertiesTest { assertThat(expected.getShowInLauncher()).isEqualTo(actual.getShowInLauncher()); assertThat(expected.getStartWithParent()).isEqualTo(actual.getStartWithParent()); assertThat(expected.getShowInSettings()).isEqualTo(actual.getShowInSettings()); assertThat(expected.getInheritDevicePolicy()).isEqualTo( actual.getInheritDevicePolicy()); } } services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java +1 −0 Original line number Diff line number Diff line Loading @@ -601,6 +601,7 @@ public final class UserManagerTest { assertThat(userProps.getShowInLauncher()).isEqualTo(typeProps.getShowInLauncher()); assertThat(userProps.getShowInSettings()).isEqualTo(typeProps.getShowInSettings()); assertThrows(SecurityException.class, userProps::getStartWithParent); assertThrows(SecurityException.class, userProps::getInheritDevicePolicy); } // Make sure only max managed profiles can be created Loading Loading
core/java/android/content/pm/UserProperties.java +81 −2 Original line number Diff line number Diff line Loading @@ -44,12 +44,14 @@ public final class UserProperties implements Parcelable { private static final String ATTR_SHOW_IN_LAUNCHER = "showInLauncher"; private static final String ATTR_START_WITH_PARENT = "startWithParent"; private static final String ATTR_SHOW_IN_SETTINGS = "showInSettings"; private static final String ATTR_INHERIT_DEVICE_POLICY = "inheritDevicePolicy"; /** Index values of each property (to indicate whether they are present in this object). */ @IntDef(prefix = "INDEX_", value = { INDEX_SHOW_IN_LAUNCHER, INDEX_START_WITH_PARENT, INDEX_SHOW_IN_SETTINGS, INDEX_INHERIT_DEVICE_POLICY, }) @Retention(RetentionPolicy.SOURCE) private @interface PropertyIndex { Loading @@ -57,6 +59,7 @@ public final class UserProperties implements Parcelable { private static final int INDEX_SHOW_IN_LAUNCHER = 0; private static final int INDEX_START_WITH_PARENT = 1; private static final int INDEX_SHOW_IN_SETTINGS = 2; private static final int INDEX_INHERIT_DEVICE_POLICY = 3; /** A bit set, mapping each PropertyIndex to whether it is present (1) or absent (0). */ private long mPropertiesPresent = 0; Loading Loading @@ -120,6 +123,37 @@ public final class UserProperties implements Parcelable { */ public static final int SHOW_IN_SETTINGS_NO = 2; /** * Possible values for whether (and from whom) to inherit select user restrictions * or device policies. * * @hide */ @IntDef(prefix = "INHERIT_DEVICE_POLICY", value = { INHERIT_DEVICE_POLICY_NO, INHERIT_DEVICE_POLICY_FROM_PARENT, }) @Retention(RetentionPolicy.SOURCE) public @interface InheritDevicePolicy { } /** * Suggests that the given user profile should not inherit user restriction or device policy * from any other user. This is the default value for any new user type. * @hide */ public static final int INHERIT_DEVICE_POLICY_NO = 0; /** * Suggests that the given user profile should inherit select user restrictions or * device policies from its parent profile. * *<p> All the user restrictions and device policies would be not propagated to the profile * with this property value. The {(TODO:b/256978256) @link DevicePolicyEngine} * uses this property to determine and propagate only select ones to the given profile. * * @hide */ public static final int INHERIT_DEVICE_POLICY_FROM_PARENT = 1; /** * Reference to the default user properties for this user's user type. * <li>If non-null, then any absent property will use the default property from here instead. Loading Loading @@ -161,6 +195,7 @@ public final class UserProperties implements Parcelable { if (exposeAllFields) { // Add items that require exposeAllFields to be true (strictest permission level). setStartWithParent(orig.getStartWithParent()); setInheritDevicePolicy(orig.getInheritDevicePolicy()); } if (hasManagePermission) { // Add items that require MANAGE_USERS or stronger. Loading Loading @@ -261,6 +296,27 @@ public final class UserProperties implements Parcelable { } private boolean mStartWithParent; /** * Return whether, and how, select user restrictions or device policies should be inherited * from other user. * * Possible return values include * {@link #INHERIT_DEVICE_POLICY_FROM_PARENT} or {@link #INHERIT_DEVICE_POLICY_NO} * * @hide */ public @InheritDevicePolicy int getInheritDevicePolicy() { if (isPresent(INDEX_INHERIT_DEVICE_POLICY)) return mInheritDevicePolicy; if (mDefaultProperties != null) return mDefaultProperties.mInheritDevicePolicy; throw new SecurityException("You don't have permission to query inheritDevicePolicy"); } /** @hide */ public void setInheritDevicePolicy(@InheritDevicePolicy int val) { this.mInheritDevicePolicy = val; setPresent(INDEX_INHERIT_DEVICE_POLICY); } private @InheritDevicePolicy int mInheritDevicePolicy; @Override public String toString() { // Please print in increasing order of PropertyIndex. Loading @@ -269,6 +325,7 @@ public final class UserProperties implements Parcelable { + ", mShowInLauncher=" + getShowInLauncher() + ", mStartWithParent=" + getStartWithParent() + ", mShowInSettings=" + getShowInSettings() + ", mInheritDevicePolicy=" + getInheritDevicePolicy() + "}"; } Loading @@ -283,6 +340,7 @@ public final class UserProperties implements Parcelable { pw.println(prefix + " mShowInLauncher=" + getShowInLauncher()); pw.println(prefix + " mStartWithParent=" + getStartWithParent()); pw.println(prefix + " mShowInSettings=" + getShowInSettings()); pw.println(prefix + " mInheritDevicePolicy=" + getInheritDevicePolicy()); } /** Loading Loading @@ -324,6 +382,10 @@ public final class UserProperties implements Parcelable { break; case ATTR_SHOW_IN_SETTINGS: setShowInSettings(parser.getAttributeInt(i)); break; case ATTR_INHERIT_DEVICE_POLICY: setInheritDevicePolicy(parser.getAttributeInt(i)); break; default: Slog.w(LOG_TAG, "Skipping unknown property " + attributeName); } Loading @@ -350,6 +412,10 @@ public final class UserProperties implements Parcelable { if (isPresent(INDEX_SHOW_IN_SETTINGS)) { serializer.attributeInt(null, ATTR_SHOW_IN_SETTINGS, mShowInSettings); } if (isPresent(INDEX_INHERIT_DEVICE_POLICY)) { serializer.attributeInt(null, ATTR_INHERIT_DEVICE_POLICY, mInheritDevicePolicy); } } // For use only with an object that has already had any permission-lacking fields stripped out. Loading @@ -359,6 +425,7 @@ public final class UserProperties implements Parcelable { dest.writeInt(mShowInLauncher); dest.writeBoolean(mStartWithParent); dest.writeInt(mShowInSettings); dest.writeInt(mInheritDevicePolicy); } /** Loading @@ -372,6 +439,7 @@ public final class UserProperties implements Parcelable { mShowInLauncher = source.readInt(); mStartWithParent = source.readBoolean(); mShowInSettings = source.readInt(); mInheritDevicePolicy = source.readInt(); } @Override Loading Loading @@ -399,6 +467,7 @@ public final class UserProperties implements Parcelable { private @ShowInLauncher int mShowInLauncher = SHOW_IN_LAUNCHER_WITH_PARENT; private boolean mStartWithParent = false; private @ShowInSettings int mShowInSettings = SHOW_IN_SETTINGS_WITH_PARENT; private @InheritDevicePolicy int mInheritDevicePolicy = INHERIT_DEVICE_POLICY_NO; public Builder setShowInLauncher(@ShowInLauncher int showInLauncher) { mShowInLauncher = showInLauncher; Loading @@ -416,12 +485,20 @@ public final class UserProperties implements Parcelable { return this; } /** Sets the value for {@link #mInheritDevicePolicy}*/ public Builder setInheritDevicePolicy( @InheritDevicePolicy int inheritRestrictionsDevicePolicy) { mInheritDevicePolicy = inheritRestrictionsDevicePolicy; return this; } /** Builds a UserProperties object with *all* values populated. */ public UserProperties build() { return new UserProperties( mShowInLauncher, mStartWithParent, mShowInSettings); mShowInSettings, mInheritDevicePolicy); } } // end Builder Loading @@ -429,11 +506,13 @@ public final class UserProperties implements Parcelable { private UserProperties( @ShowInLauncher int showInLauncher, boolean startWithParent, @ShowInSettings int showInSettings) { @ShowInSettings int showInSettings, @InheritDevicePolicy int inheritDevicePolicy) { mDefaultProperties = null; setShowInLauncher(showInLauncher); setStartWithParent(startWithParent); setShowInSettings(showInSettings); setInheritDevicePolicy(inheritDevicePolicy); } }
services/core/java/com/android/server/pm/UserTypeFactory.java +2 −1 Original line number Diff line number Diff line Loading @@ -129,7 +129,8 @@ public final class UserTypeFactory { .setDefaultUserProperties(new UserProperties.Builder() .setStartWithParent(true) .setShowInLauncher(UserProperties.SHOW_IN_LAUNCHER_WITH_PARENT) .setShowInSettings(UserProperties.SHOW_IN_SETTINGS_WITH_PARENT)); .setShowInSettings(UserProperties.SHOW_IN_SETTINGS_WITH_PARENT) .setInheritDevicePolicy(UserProperties.INHERIT_DEVICE_POLICY_FROM_PARENT)); } /** Loading
services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserPropertiesTest.java +8 −0 Original line number Diff line number Diff line Loading @@ -60,10 +60,12 @@ public class UserManagerServiceUserPropertiesTest { .setShowInLauncher(21) .setStartWithParent(false) .setShowInSettings(45) .setInheritDevicePolicy(67) .build(); final UserProperties actualProps = new UserProperties(defaultProps); actualProps.setShowInLauncher(14); actualProps.setShowInSettings(32); actualProps.setInheritDevicePolicy(51); // Write the properties to xml. final ByteArrayOutputStream baos = new ByteArrayOutputStream(); Loading Loading @@ -102,11 +104,13 @@ public class UserManagerServiceUserPropertiesTest { .setShowInLauncher(2145) .setStartWithParent(true) .setShowInSettings(3452) .setInheritDevicePolicy(1732) .build(); final UserProperties orig = new UserProperties(defaultProps); orig.setShowInLauncher(2841); orig.setStartWithParent(false); orig.setShowInSettings(1437); orig.setInheritDevicePolicy(9456); // Test every permission level. (Currently, it's linear so it's easy.) for (int permLevel = 0; permLevel < 4; permLevel++) { Loading Loading @@ -142,6 +146,8 @@ public class UserManagerServiceUserPropertiesTest { // Items requiring exposeAll. assertEqualGetterOrThrows(orig::getStartWithParent, copy::getStartWithParent, exposeAll); assertEqualGetterOrThrows(orig::getInheritDevicePolicy, copy::getInheritDevicePolicy, exposeAll); // Items requiring hasManagePermission - put them here using hasManagePermission. assertEqualGetterOrThrows(orig::getShowInSettings, copy::getShowInSettings, Loading Loading @@ -190,5 +196,7 @@ public class UserManagerServiceUserPropertiesTest { assertThat(expected.getShowInLauncher()).isEqualTo(actual.getShowInLauncher()); assertThat(expected.getStartWithParent()).isEqualTo(actual.getStartWithParent()); assertThat(expected.getShowInSettings()).isEqualTo(actual.getShowInSettings()); assertThat(expected.getInheritDevicePolicy()).isEqualTo( actual.getInheritDevicePolicy()); } }
services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java +1 −0 Original line number Diff line number Diff line Loading @@ -601,6 +601,7 @@ public final class UserManagerTest { assertThat(userProps.getShowInLauncher()).isEqualTo(typeProps.getShowInLauncher()); assertThat(userProps.getShowInSettings()).isEqualTo(typeProps.getShowInSettings()); assertThrows(SecurityException.class, userProps::getStartWithParent); assertThrows(SecurityException.class, userProps::getInheritDevicePolicy); } // Make sure only max managed profiles can be created Loading