Loading core/java/android/content/pm/UserProperties.java +83 −2 Original line number Diff line number Diff line Loading @@ -43,17 +43,20 @@ public final class UserProperties implements Parcelable { // Attribute strings for reading/writing properties to/from XML. 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"; /** 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, }) @Retention(RetentionPolicy.SOURCE) private @interface PropertyIndex { } 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; /** A bit set, mapping each PropertyIndex to whether it is present (1) or absent (0). */ private long mPropertiesPresent = 0; Loading Loading @@ -86,6 +89,37 @@ public final class UserProperties implements Parcelable { */ public static final int SHOW_IN_LAUNCHER_NO = 2; /** * Possible values for whether or how to show this user in the Settings app. * @hide */ @IntDef(prefix = "SHOW_IN_SETTINGS_", value = { SHOW_IN_SETTINGS_WITH_PARENT, SHOW_IN_SETTINGS_SEPARATE, SHOW_IN_SETTINGS_NO, }) @Retention(RetentionPolicy.SOURCE) public @interface ShowInSettings { } /** * Suggests that the Settings app should show this user's apps in the main tab. * That is, either this user is a full user, so its apps should be presented accordingly, or, if * this user is a profile, then its apps should be shown alongside its parent's apps. * @hide */ public static final int SHOW_IN_SETTINGS_WITH_PARENT = 0; /** * Suggests that the Settings app should show this user's apps, but separately from the apps of * this user's parent. * @hide */ public static final int SHOW_IN_SETTINGS_SEPARATE = 1; /** * Suggests that the Settings app should not show this user. * @hide */ public static final int SHOW_IN_SETTINGS_NO = 2; /** * 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 @@ -130,6 +164,7 @@ public final class UserProperties implements Parcelable { } if (hasManagePermission) { // Add items that require MANAGE_USERS or stronger. setShowInSettings(orig.getShowInSettings()); } if (hasQueryOrManagePermission) { // Add items that require QUERY_USERS or stronger. Loading Loading @@ -182,6 +217,33 @@ public final class UserProperties implements Parcelable { } private @ShowInLauncher int mShowInLauncher; /** * Returns whether, and how, a user should be shown in the Settings app. * This is generally inapplicable for non-profile users. * * Possible return values include * {@link #SHOW_IN_SETTINGS_WITH_PARENT}}, * {@link #SHOW_IN_SETTINGS_SEPARATE}, * and {@link #SHOW_IN_SETTINGS_NO}. * * <p> The caller must have {@link android.Manifest.permission#MANAGE_USERS} to query this * property. * * @return whether, and how, a profile should be shown in the Settings. * @hide */ public @ShowInSettings int getShowInSettings() { if (isPresent(INDEX_SHOW_IN_SETTINGS)) return mShowInSettings; if (mDefaultProperties != null) return mDefaultProperties.mShowInSettings; throw new SecurityException("You don't have permission to query mShowInSettings"); } /** @hide */ public void setShowInSettings(@ShowInSettings int val) { this.mShowInSettings = val; setPresent(INDEX_SHOW_IN_SETTINGS); } private @ShowInSettings int mShowInSettings; /** * Returns whether a profile should be started when its parent starts (unless in quiet mode). * This only applies for users that have parents (i.e. for profiles). Loading @@ -206,6 +268,7 @@ public final class UserProperties implements Parcelable { + "mPropertiesPresent=" + Long.toBinaryString(mPropertiesPresent) + ", mShowInLauncher=" + getShowInLauncher() + ", mStartWithParent=" + getStartWithParent() + ", mShowInSettings=" + getShowInSettings() + "}"; } Loading @@ -219,6 +282,7 @@ public final class UserProperties implements Parcelable { pw.println(prefix + " mPropertiesPresent=" + Long.toBinaryString(mPropertiesPresent)); pw.println(prefix + " mShowInLauncher=" + getShowInLauncher()); pw.println(prefix + " mStartWithParent=" + getStartWithParent()); pw.println(prefix + " mShowInSettings=" + getShowInSettings()); } /** Loading Loading @@ -258,6 +322,8 @@ public final class UserProperties implements Parcelable { case ATTR_START_WITH_PARENT: setStartWithParent(parser.getAttributeBoolean(i)); break; case ATTR_SHOW_IN_SETTINGS: setShowInSettings(parser.getAttributeInt(i)); default: Slog.w(LOG_TAG, "Skipping unknown property " + attributeName); } Loading @@ -281,6 +347,9 @@ public final class UserProperties implements Parcelable { if (isPresent(INDEX_START_WITH_PARENT)) { serializer.attributeBoolean(null, ATTR_START_WITH_PARENT, mStartWithParent); } if (isPresent(INDEX_SHOW_IN_SETTINGS)) { serializer.attributeInt(null, ATTR_SHOW_IN_SETTINGS, mShowInSettings); } } // For use only with an object that has already had any permission-lacking fields stripped out. Loading @@ -289,6 +358,7 @@ public final class UserProperties implements Parcelable { dest.writeLong(mPropertiesPresent); dest.writeInt(mShowInLauncher); dest.writeBoolean(mStartWithParent); dest.writeInt(mShowInSettings); } /** Loading @@ -301,6 +371,7 @@ public final class UserProperties implements Parcelable { mPropertiesPresent = source.readLong(); mShowInLauncher = source.readInt(); mStartWithParent = source.readBoolean(); mShowInSettings = source.readInt(); } @Override Loading @@ -327,6 +398,7 @@ public final class UserProperties implements Parcelable { // UserProperties fields and their default values. private @ShowInLauncher int mShowInLauncher = SHOW_IN_LAUNCHER_WITH_PARENT; private boolean mStartWithParent = false; private @ShowInSettings int mShowInSettings = SHOW_IN_SETTINGS_WITH_PARENT; public Builder setShowInLauncher(@ShowInLauncher int showInLauncher) { mShowInLauncher = showInLauncher; Loading @@ -338,21 +410,30 @@ public final class UserProperties implements Parcelable { return this; } /** Sets the value for {@link #mShowInSettings} */ public Builder setShowInSettings(@ShowInSettings int showInSettings) { mShowInSettings = showInSettings; return this; } /** Builds a UserProperties object with *all* values populated. */ public UserProperties build() { return new UserProperties( mShowInLauncher, mStartWithParent); mStartWithParent, mShowInSettings); } } // end Builder /** Creates a UserProperties with the given properties. Intended for building default values. */ private UserProperties( @ShowInLauncher int showInLauncher, boolean startWithParent) { boolean startWithParent, @ShowInSettings int showInSettings) { mDefaultProperties = null; setShowInLauncher(showInLauncher); setStartWithParent(startWithParent); setShowInSettings(showInSettings); } } services/core/java/com/android/server/pm/UserTypeFactory.java +4 −2 Original line number Diff line number Diff line Loading @@ -128,7 +128,8 @@ public final class UserTypeFactory { .setIsCredentialSharableWithParent(true) .setDefaultUserProperties(new UserProperties.Builder() .setStartWithParent(true) .setShowInLauncher(UserProperties.SHOW_IN_LAUNCHER_WITH_PARENT)); .setShowInLauncher(UserProperties.SHOW_IN_LAUNCHER_WITH_PARENT) .setShowInSettings(UserProperties.SHOW_IN_SETTINGS_WITH_PARENT)); } /** Loading Loading @@ -163,7 +164,8 @@ public final class UserTypeFactory { .setIsCredentialSharableWithParent(true) .setDefaultUserProperties(new UserProperties.Builder() .setStartWithParent(true) .setShowInLauncher(UserProperties.SHOW_IN_LAUNCHER_SEPARATE)); .setShowInLauncher(UserProperties.SHOW_IN_LAUNCHER_SEPARATE) .setShowInSettings(UserProperties.SHOW_IN_SETTINGS_SEPARATE)); } /** Loading services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserPropertiesTest.java +8 −0 Original line number Diff line number Diff line Loading @@ -59,9 +59,11 @@ public class UserManagerServiceUserPropertiesTest { final UserProperties defaultProps = new UserProperties.Builder() .setShowInLauncher(21) .setStartWithParent(false) .setShowInSettings(45) .build(); final UserProperties actualProps = new UserProperties(defaultProps); actualProps.setShowInLauncher(14); actualProps.setShowInSettings(32); // Write the properties to xml. final ByteArrayOutputStream baos = new ByteArrayOutputStream(); Loading Loading @@ -99,10 +101,12 @@ public class UserManagerServiceUserPropertiesTest { final UserProperties defaultProps = new UserProperties.Builder() .setShowInLauncher(2145) .setStartWithParent(true) .setShowInSettings(3452) .build(); final UserProperties orig = new UserProperties(defaultProps); orig.setShowInLauncher(2841); orig.setStartWithParent(false); orig.setShowInSettings(1437); // Test every permission level. (Currently, it's linear so it's easy.) for (int permLevel = 0; permLevel < 4; permLevel++) { Loading Loading @@ -140,6 +144,9 @@ public class UserManagerServiceUserPropertiesTest { assertEqualGetterOrThrows(orig::getStartWithParent, copy::getStartWithParent, exposeAll); // Items requiring hasManagePermission - put them here using hasManagePermission. assertEqualGetterOrThrows(orig::getShowInSettings, copy::getShowInSettings, hasManagePermission); // Items requiring hasQueryPermission - put them here using hasQueryPermission. // Items with no permission requirements. Loading Loading @@ -182,5 +189,6 @@ public class UserManagerServiceUserPropertiesTest { assertThat(expected.getPropertiesPresent()).isEqualTo(actual.getPropertiesPresent()); assertThat(expected.getShowInLauncher()).isEqualTo(actual.getShowInLauncher()); assertThat(expected.getStartWithParent()).isEqualTo(actual.getStartWithParent()); assertThat(expected.getShowInSettings()).isEqualTo(actual.getShowInSettings()); } } services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java +1 −0 Original line number Diff line number Diff line Loading @@ -599,6 +599,7 @@ public final class UserManagerTest { // Check that this new user has the expected properties (relative to the defaults) // provided that the test caller has the necessary permissions. assertThat(userProps.getShowInLauncher()).isEqualTo(typeProps.getShowInLauncher()); assertThat(userProps.getShowInSettings()).isEqualTo(typeProps.getShowInSettings()); assertThrows(SecurityException.class, userProps::getStartWithParent); } Loading Loading
core/java/android/content/pm/UserProperties.java +83 −2 Original line number Diff line number Diff line Loading @@ -43,17 +43,20 @@ public final class UserProperties implements Parcelable { // Attribute strings for reading/writing properties to/from XML. 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"; /** 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, }) @Retention(RetentionPolicy.SOURCE) private @interface PropertyIndex { } 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; /** A bit set, mapping each PropertyIndex to whether it is present (1) or absent (0). */ private long mPropertiesPresent = 0; Loading Loading @@ -86,6 +89,37 @@ public final class UserProperties implements Parcelable { */ public static final int SHOW_IN_LAUNCHER_NO = 2; /** * Possible values for whether or how to show this user in the Settings app. * @hide */ @IntDef(prefix = "SHOW_IN_SETTINGS_", value = { SHOW_IN_SETTINGS_WITH_PARENT, SHOW_IN_SETTINGS_SEPARATE, SHOW_IN_SETTINGS_NO, }) @Retention(RetentionPolicy.SOURCE) public @interface ShowInSettings { } /** * Suggests that the Settings app should show this user's apps in the main tab. * That is, either this user is a full user, so its apps should be presented accordingly, or, if * this user is a profile, then its apps should be shown alongside its parent's apps. * @hide */ public static final int SHOW_IN_SETTINGS_WITH_PARENT = 0; /** * Suggests that the Settings app should show this user's apps, but separately from the apps of * this user's parent. * @hide */ public static final int SHOW_IN_SETTINGS_SEPARATE = 1; /** * Suggests that the Settings app should not show this user. * @hide */ public static final int SHOW_IN_SETTINGS_NO = 2; /** * 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 @@ -130,6 +164,7 @@ public final class UserProperties implements Parcelable { } if (hasManagePermission) { // Add items that require MANAGE_USERS or stronger. setShowInSettings(orig.getShowInSettings()); } if (hasQueryOrManagePermission) { // Add items that require QUERY_USERS or stronger. Loading Loading @@ -182,6 +217,33 @@ public final class UserProperties implements Parcelable { } private @ShowInLauncher int mShowInLauncher; /** * Returns whether, and how, a user should be shown in the Settings app. * This is generally inapplicable for non-profile users. * * Possible return values include * {@link #SHOW_IN_SETTINGS_WITH_PARENT}}, * {@link #SHOW_IN_SETTINGS_SEPARATE}, * and {@link #SHOW_IN_SETTINGS_NO}. * * <p> The caller must have {@link android.Manifest.permission#MANAGE_USERS} to query this * property. * * @return whether, and how, a profile should be shown in the Settings. * @hide */ public @ShowInSettings int getShowInSettings() { if (isPresent(INDEX_SHOW_IN_SETTINGS)) return mShowInSettings; if (mDefaultProperties != null) return mDefaultProperties.mShowInSettings; throw new SecurityException("You don't have permission to query mShowInSettings"); } /** @hide */ public void setShowInSettings(@ShowInSettings int val) { this.mShowInSettings = val; setPresent(INDEX_SHOW_IN_SETTINGS); } private @ShowInSettings int mShowInSettings; /** * Returns whether a profile should be started when its parent starts (unless in quiet mode). * This only applies for users that have parents (i.e. for profiles). Loading @@ -206,6 +268,7 @@ public final class UserProperties implements Parcelable { + "mPropertiesPresent=" + Long.toBinaryString(mPropertiesPresent) + ", mShowInLauncher=" + getShowInLauncher() + ", mStartWithParent=" + getStartWithParent() + ", mShowInSettings=" + getShowInSettings() + "}"; } Loading @@ -219,6 +282,7 @@ public final class UserProperties implements Parcelable { pw.println(prefix + " mPropertiesPresent=" + Long.toBinaryString(mPropertiesPresent)); pw.println(prefix + " mShowInLauncher=" + getShowInLauncher()); pw.println(prefix + " mStartWithParent=" + getStartWithParent()); pw.println(prefix + " mShowInSettings=" + getShowInSettings()); } /** Loading Loading @@ -258,6 +322,8 @@ public final class UserProperties implements Parcelable { case ATTR_START_WITH_PARENT: setStartWithParent(parser.getAttributeBoolean(i)); break; case ATTR_SHOW_IN_SETTINGS: setShowInSettings(parser.getAttributeInt(i)); default: Slog.w(LOG_TAG, "Skipping unknown property " + attributeName); } Loading @@ -281,6 +347,9 @@ public final class UserProperties implements Parcelable { if (isPresent(INDEX_START_WITH_PARENT)) { serializer.attributeBoolean(null, ATTR_START_WITH_PARENT, mStartWithParent); } if (isPresent(INDEX_SHOW_IN_SETTINGS)) { serializer.attributeInt(null, ATTR_SHOW_IN_SETTINGS, mShowInSettings); } } // For use only with an object that has already had any permission-lacking fields stripped out. Loading @@ -289,6 +358,7 @@ public final class UserProperties implements Parcelable { dest.writeLong(mPropertiesPresent); dest.writeInt(mShowInLauncher); dest.writeBoolean(mStartWithParent); dest.writeInt(mShowInSettings); } /** Loading @@ -301,6 +371,7 @@ public final class UserProperties implements Parcelable { mPropertiesPresent = source.readLong(); mShowInLauncher = source.readInt(); mStartWithParent = source.readBoolean(); mShowInSettings = source.readInt(); } @Override Loading @@ -327,6 +398,7 @@ public final class UserProperties implements Parcelable { // UserProperties fields and their default values. private @ShowInLauncher int mShowInLauncher = SHOW_IN_LAUNCHER_WITH_PARENT; private boolean mStartWithParent = false; private @ShowInSettings int mShowInSettings = SHOW_IN_SETTINGS_WITH_PARENT; public Builder setShowInLauncher(@ShowInLauncher int showInLauncher) { mShowInLauncher = showInLauncher; Loading @@ -338,21 +410,30 @@ public final class UserProperties implements Parcelable { return this; } /** Sets the value for {@link #mShowInSettings} */ public Builder setShowInSettings(@ShowInSettings int showInSettings) { mShowInSettings = showInSettings; return this; } /** Builds a UserProperties object with *all* values populated. */ public UserProperties build() { return new UserProperties( mShowInLauncher, mStartWithParent); mStartWithParent, mShowInSettings); } } // end Builder /** Creates a UserProperties with the given properties. Intended for building default values. */ private UserProperties( @ShowInLauncher int showInLauncher, boolean startWithParent) { boolean startWithParent, @ShowInSettings int showInSettings) { mDefaultProperties = null; setShowInLauncher(showInLauncher); setStartWithParent(startWithParent); setShowInSettings(showInSettings); } }
services/core/java/com/android/server/pm/UserTypeFactory.java +4 −2 Original line number Diff line number Diff line Loading @@ -128,7 +128,8 @@ public final class UserTypeFactory { .setIsCredentialSharableWithParent(true) .setDefaultUserProperties(new UserProperties.Builder() .setStartWithParent(true) .setShowInLauncher(UserProperties.SHOW_IN_LAUNCHER_WITH_PARENT)); .setShowInLauncher(UserProperties.SHOW_IN_LAUNCHER_WITH_PARENT) .setShowInSettings(UserProperties.SHOW_IN_SETTINGS_WITH_PARENT)); } /** Loading Loading @@ -163,7 +164,8 @@ public final class UserTypeFactory { .setIsCredentialSharableWithParent(true) .setDefaultUserProperties(new UserProperties.Builder() .setStartWithParent(true) .setShowInLauncher(UserProperties.SHOW_IN_LAUNCHER_SEPARATE)); .setShowInLauncher(UserProperties.SHOW_IN_LAUNCHER_SEPARATE) .setShowInSettings(UserProperties.SHOW_IN_SETTINGS_SEPARATE)); } /** Loading
services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserPropertiesTest.java +8 −0 Original line number Diff line number Diff line Loading @@ -59,9 +59,11 @@ public class UserManagerServiceUserPropertiesTest { final UserProperties defaultProps = new UserProperties.Builder() .setShowInLauncher(21) .setStartWithParent(false) .setShowInSettings(45) .build(); final UserProperties actualProps = new UserProperties(defaultProps); actualProps.setShowInLauncher(14); actualProps.setShowInSettings(32); // Write the properties to xml. final ByteArrayOutputStream baos = new ByteArrayOutputStream(); Loading Loading @@ -99,10 +101,12 @@ public class UserManagerServiceUserPropertiesTest { final UserProperties defaultProps = new UserProperties.Builder() .setShowInLauncher(2145) .setStartWithParent(true) .setShowInSettings(3452) .build(); final UserProperties orig = new UserProperties(defaultProps); orig.setShowInLauncher(2841); orig.setStartWithParent(false); orig.setShowInSettings(1437); // Test every permission level. (Currently, it's linear so it's easy.) for (int permLevel = 0; permLevel < 4; permLevel++) { Loading Loading @@ -140,6 +144,9 @@ public class UserManagerServiceUserPropertiesTest { assertEqualGetterOrThrows(orig::getStartWithParent, copy::getStartWithParent, exposeAll); // Items requiring hasManagePermission - put them here using hasManagePermission. assertEqualGetterOrThrows(orig::getShowInSettings, copy::getShowInSettings, hasManagePermission); // Items requiring hasQueryPermission - put them here using hasQueryPermission. // Items with no permission requirements. Loading Loading @@ -182,5 +189,6 @@ public class UserManagerServiceUserPropertiesTest { assertThat(expected.getPropertiesPresent()).isEqualTo(actual.getPropertiesPresent()); assertThat(expected.getShowInLauncher()).isEqualTo(actual.getShowInLauncher()); assertThat(expected.getStartWithParent()).isEqualTo(actual.getStartWithParent()); assertThat(expected.getShowInSettings()).isEqualTo(actual.getShowInSettings()); } }
services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java +1 −0 Original line number Diff line number Diff line Loading @@ -599,6 +599,7 @@ public final class UserManagerTest { // Check that this new user has the expected properties (relative to the defaults) // provided that the test caller has the necessary permissions. assertThat(userProps.getShowInLauncher()).isEqualTo(typeProps.getShowInLauncher()); assertThat(userProps.getShowInSettings()).isEqualTo(typeProps.getShowInSettings()); assertThrows(SecurityException.class, userProps::getStartWithParent); } Loading