Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0dea4a66 authored by Himanshu Gupta's avatar Himanshu Gupta
Browse files

Adding UserProperty for Restricting PS Items on home screen.

This property will be used to restrict the addition of items
such as such as Apps Pending Installation, Widgets, Custom App
Shortcuts, etc. on Launcher home screen.

Primary use case if for users/profiles which have restricted
visibility in all surfaces due to product definition (such as
private profile) for which icons placed on home screen can be
a giveaway for the the presence of a separate app installation
space.
For such profiles, this property can be set as true (default value
is false), and accordingly framework APIs will restrict
information about home screen items to Launcher(s).

Bug: 287975131
Test: atest UserManagerServiceUserPropertiesTest
Test: atest UserManagerServiceUserTypeTest
Test: atest FrameworksServicesTests:UserManagerTest
Change-Id: Iab0805bd92d43bf31cc12ae17f748800d0c40139
parent 65a793a8
Loading
Loading
Loading
Loading
+65 −4
Original line number Diff line number Diff line
@@ -77,6 +77,8 @@ public final class UserProperties implements Parcelable {
    private static final String ATTR_CROSS_PROFILE_CONTENT_SHARING_STRATEGY =
            "crossProfileContentSharingStrategy";
    private static final String ATTR_PROFILE_API_VISIBILITY = "profileApiVisibility";
    private static final String ITEMS_RESTRICTED_ON_HOME_SCREEN =
            "itemsRestrictedOnHomeScreen";
    /** Index values of each property (to indicate whether they are present in this object). */
    @IntDef(prefix = "INDEX_", value = {
            INDEX_SHOW_IN_LAUNCHER,
@@ -96,7 +98,8 @@ public final class UserProperties implements Parcelable {
            INDEX_AUTH_ALWAYS_REQUIRED_TO_DISABLE_QUIET_MODE,
            INDEX_CROSS_PROFILE_CONTENT_SHARING_STRATEGY,
            INDEX_ALLOW_STOPPING_USER_WITH_DELAYED_LOCKING,
            INDEX_PROFILE_API_VISIBILITY
            INDEX_PROFILE_API_VISIBILITY,
            INDEX_ITEMS_RESTRICTED_ON_HOME_SCREEN
    })
    @Retention(RetentionPolicy.SOURCE)
    private @interface PropertyIndex {
@@ -119,6 +122,7 @@ public final class UserProperties implements Parcelable {
    private static final int INDEX_CROSS_PROFILE_CONTENT_SHARING_STRATEGY = 15;
    private static final int INDEX_ALLOW_STOPPING_USER_WITH_DELAYED_LOCKING = 16;
    private static final int INDEX_PROFILE_API_VISIBILITY = 17;
    private static final int INDEX_ITEMS_RESTRICTED_ON_HOME_SCREEN = 18;
    /** A bit set, mapping each PropertyIndex to whether it is present (1) or absent (0). */
    private long mPropertiesPresent = 0;

@@ -532,6 +536,7 @@ public final class UserProperties implements Parcelable {
            setDeleteAppWithParent(orig.getDeleteAppWithParent());
            setAlwaysVisible(orig.getAlwaysVisible());
            setAllowStoppingUserWithDelayedLocking(orig.getAllowStoppingUserWithDelayedLocking());
            setItemsRestrictedOnHomeScreen(orig.areItemsRestrictedOnHomeScreen());
        }
        if (hasManagePermission) {
            // Add items that require MANAGE_USERS or stronger.
@@ -1014,6 +1019,38 @@ public final class UserProperties implements Parcelable {
    }
    private @ProfileApiVisibility int mProfileApiVisibility;

    /**
     * Returns whether a user (usually a profile) is allowed to have items such as Apps Pending
     * Installation, Widgets, Custom App Shortcuts, etc. on Launcher home screen.
     *
     * <p> For a typical user/profile, this property will be false, allowing framework APIs to
     * provide information about such items to Launcher(s). When set true, framework APIs will
     * restrict the same.
     *
     * <p> This property only restricts information about items that are accessed solely via the
     * Launcher home screen. Information about items such as App Icons, Deep Links, which can also
     * be accessed via other launcher components, such as All Apps Drawer is not restricted by this
     * property.
     *
     * @hide
     */
    public boolean areItemsRestrictedOnHomeScreen() {
        if (isPresent(INDEX_ITEMS_RESTRICTED_ON_HOME_SCREEN)) {
            return mItemsRestrictedOnHomeScreen;
        }
        if (mDefaultProperties != null) {
            return mDefaultProperties.mItemsRestrictedOnHomeScreen;
        }
        throw new SecurityException(
                "You don't have permission to query mItemsRestrictedOnHomeScreen");
    }
    /** @hide */
    public void setItemsRestrictedOnHomeScreen(boolean val) {
        this.mItemsRestrictedOnHomeScreen = val;
        setPresent(INDEX_ITEMS_RESTRICTED_ON_HOME_SCREEN);
    }
    private boolean mItemsRestrictedOnHomeScreen;

    @Override
    public String toString() {
        String profileApiVisibility =
@@ -1042,7 +1079,8 @@ public final class UserProperties implements Parcelable {
                + ", mDeleteAppWithParent=" + getDeleteAppWithParent()
                + ", mAlwaysVisible=" + getAlwaysVisible()
                + ", mCrossProfileContentSharingStrategy=" + getCrossProfileContentSharingStrategy()
                + profileApiVisibility
                + ", mProfileApiVisibility=" + profileApiVisibility
                + ", mItemsRestrictedOnHomeScreen=" + areItemsRestrictedOnHomeScreen()
                + "}";
    }

@@ -1079,6 +1117,7 @@ public final class UserProperties implements Parcelable {
        if (android.multiuser.Flags.supportHidingProfiles()) {
            pw.println(prefix + "    mProfileApiVisibility=" + getProfileApiVisibility());
        }
        pw.println(prefix + "    mItemsRestrictedOnHomeScreen=" + areItemsRestrictedOnHomeScreen());
    }

    /**
@@ -1168,6 +1207,9 @@ public final class UserProperties implements Parcelable {
                        setProfileApiVisibility(parser.getAttributeInt(i));
                    }
                    break;
                case ITEMS_RESTRICTED_ON_HOME_SCREEN:
                    setItemsRestrictedOnHomeScreen(parser.getAttributeBoolean(i));
                    break;
                default:
                    Slog.w(LOG_TAG, "Skipping unknown property " + attributeName);
            }
@@ -1256,6 +1298,10 @@ public final class UserProperties implements Parcelable {
                        mProfileApiVisibility);
            }
        }
        if (isPresent(INDEX_ITEMS_RESTRICTED_ON_HOME_SCREEN)) {
            serializer.attributeBoolean(null, ITEMS_RESTRICTED_ON_HOME_SCREEN,
                    mItemsRestrictedOnHomeScreen);
        }
    }

    // For use only with an object that has already had any permission-lacking fields stripped out.
@@ -1280,6 +1326,7 @@ public final class UserProperties implements Parcelable {
        dest.writeBoolean(mAlwaysVisible);
        dest.writeInt(mCrossProfileContentSharingStrategy);
        dest.writeInt(mProfileApiVisibility);
        dest.writeBoolean(mItemsRestrictedOnHomeScreen);
    }

    /**
@@ -1308,6 +1355,7 @@ public final class UserProperties implements Parcelable {
        mAlwaysVisible = source.readBoolean();
        mCrossProfileContentSharingStrategy = source.readInt();
        mProfileApiVisibility = source.readInt();
        mItemsRestrictedOnHomeScreen = source.readBoolean();
    }

    @Override
@@ -1358,6 +1406,7 @@ public final class UserProperties implements Parcelable {
        private @CrossProfileContentSharingStrategy int mCrossProfileContentSharingStrategy =
                CROSS_PROFILE_CONTENT_SHARING_NO_DELEGATION;
        private @ProfileApiVisibility int mProfileApiVisibility = 0;
        private boolean mItemsRestrictedOnHomeScreen = false;

        /**
         * @hide
@@ -1523,6 +1572,15 @@ public final class UserProperties implements Parcelable {
            return this;
        }

        /** Sets the value for {@link #mItemsRestrictedOnHomeScreen}
         * @hide
         */
        public Builder setItemsRestrictedOnHomeScreen(
                boolean itemsRestrictedOnHomeScreen) {
            mItemsRestrictedOnHomeScreen = itemsRestrictedOnHomeScreen;
            return this;
        }

        /** Builds a UserProperties object with *all* values populated.
         * @hide
         */
@@ -1548,7 +1606,8 @@ public final class UserProperties implements Parcelable {
                    mDeleteAppWithParent,
                    mAlwaysVisible,
                    mCrossProfileContentSharingStrategy,
                    mProfileApiVisibility);
                    mProfileApiVisibility,
                    mItemsRestrictedOnHomeScreen);
        }
    } // end Builder

@@ -1570,7 +1629,8 @@ public final class UserProperties implements Parcelable {
            boolean deleteAppWithParent,
            boolean alwaysVisible,
            @CrossProfileContentSharingStrategy int crossProfileContentSharingStrategy,
            @ProfileApiVisibility int profileApiVisibility) {
            @ProfileApiVisibility int profileApiVisibility,
            boolean itemsRestrictedOnHomeScreen) {
        mDefaultProperties = null;
        setShowInLauncher(showInLauncher);
        setStartWithParent(startWithParent);
@@ -1593,5 +1653,6 @@ public final class UserProperties implements Parcelable {
        if (android.multiuser.Flags.supportHidingProfiles()) {
            setProfileApiVisibility(profileApiVisibility);
        }
        setItemsRestrictedOnHomeScreen(itemsRestrictedOnHomeScreen);
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -304,7 +304,8 @@ public final class UserTypeFactory {
                        UserProperties.CROSS_PROFILE_INTENT_FILTER_ACCESS_LEVEL_SYSTEM)
                .setInheritDevicePolicy(UserProperties.INHERIT_DEVICE_POLICY_FROM_PARENT)
                .setCrossProfileContentSharingStrategy(
                        UserProperties.CROSS_PROFILE_CONTENT_SHARING_DELEGATE_FROM_PARENT);
                        UserProperties.CROSS_PROFILE_CONTENT_SHARING_DELEGATE_FROM_PARENT)
                .setItemsRestrictedOnHomeScreen(true);
        if (android.multiuser.Flags.supportHidingProfiles()) {
            userPropertiesBuilder.setProfileApiVisibility(
                    UserProperties.PROFILE_API_VISIBILITY_HIDDEN);
+1 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@
            deleteAppWithParent='false'
            alwaysVisible='true'
            crossProfileContentSharingStrategy='0'
            itemsRestrictedOnHomeScreen='true'
        />
    </profile-type>
    <profile-type name='custom.test.1' max-allowed-per-parent='14' />
+8 −0
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ public class UserManagerServiceUserPropertiesTest {
                .setAlwaysVisible(false)
                .setCrossProfileContentSharingStrategy(0)
                .setProfileApiVisibility(34)
                .setItemsRestrictedOnHomeScreen(false)
                .build();
        final UserProperties actualProps = new UserProperties(defaultProps);
        actualProps.setShowInLauncher(14);
@@ -97,6 +98,7 @@ public class UserManagerServiceUserPropertiesTest {
        actualProps.setAlwaysVisible(true);
        actualProps.setCrossProfileContentSharingStrategy(1);
        actualProps.setProfileApiVisibility(36);
        actualProps.setItemsRestrictedOnHomeScreen(true);

        // Write the properties to xml.
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -144,6 +146,7 @@ public class UserManagerServiceUserPropertiesTest {
                .setAllowStoppingUserWithDelayedLocking(false)
                .setAlwaysVisible(true)
                .setProfileApiVisibility(110)
                .setItemsRestrictedOnHomeScreen(false)
                .build();
        final UserProperties orig = new UserProperties(defaultProps);
        orig.setShowInLauncher(2841);
@@ -154,6 +157,7 @@ public class UserManagerServiceUserPropertiesTest {
        orig.setAuthAlwaysRequiredToDisableQuietMode(true);
        orig.setAllowStoppingUserWithDelayedLocking(true);
        orig.setAlwaysVisible(false);
        orig.setItemsRestrictedOnHomeScreen(true);

        // Test every permission level. (Currently, it's linear so it's easy.)
        for (int permLevel = 0; permLevel < 4; permLevel++) {
@@ -200,6 +204,8 @@ public class UserManagerServiceUserPropertiesTest {
        assertEqualGetterOrThrows(orig::getAlwaysVisible, copy::getAlwaysVisible, exposeAll);
        assertEqualGetterOrThrows(orig::getAllowStoppingUserWithDelayedLocking,
                copy::getAllowStoppingUserWithDelayedLocking, exposeAll);
        assertEqualGetterOrThrows(orig::areItemsRestrictedOnHomeScreen,
                copy::areItemsRestrictedOnHomeScreen, exposeAll);

        // Items requiring hasManagePermission - put them here using hasManagePermission.
        assertEqualGetterOrThrows(orig::getShowInSettings, copy::getShowInSettings,
@@ -283,5 +289,7 @@ public class UserManagerServiceUserPropertiesTest {
        assertThat(expected.getCrossProfileContentSharingStrategy())
                .isEqualTo(actual.getCrossProfileContentSharingStrategy());
        assertThat(expected.getProfileApiVisibility()).isEqualTo(actual.getProfileApiVisibility());
        assertThat(expected.areItemsRestrictedOnHomeScreen())
                .isEqualTo(actual.areItemsRestrictedOnHomeScreen());
    }
}
+7 −2
Original line number Diff line number Diff line
@@ -102,7 +102,8 @@ public class UserManagerServiceUserTypeTest {
                .setDeleteAppWithParent(true)
                .setAlwaysVisible(true)
                .setCrossProfileContentSharingStrategy(1)
                .setProfileApiVisibility(34);
                .setProfileApiVisibility(34)
                .setItemsRestrictedOnHomeScreen(true);

        final UserTypeDetails type = new UserTypeDetails.Builder()
                .setName("a.name")
@@ -186,6 +187,7 @@ public class UserManagerServiceUserTypeTest {
        assertEquals(1, type.getDefaultUserPropertiesReference()
                .getCrossProfileContentSharingStrategy());
        assertEquals(34, type.getDefaultUserPropertiesReference().getProfileApiVisibility());
        assertTrue(type.getDefaultUserPropertiesReference().areItemsRestrictedOnHomeScreen());

        assertEquals(23, type.getBadgeLabel(0));
        assertEquals(24, type.getBadgeLabel(1));
@@ -343,7 +345,8 @@ public class UserManagerServiceUserTypeTest {
                .setDeleteAppWithParent(true)
                .setAlwaysVisible(false)
                .setCrossProfileContentSharingStrategy(1)
                .setProfileApiVisibility(36);
                .setProfileApiVisibility(36)
                .setItemsRestrictedOnHomeScreen(false);

        final ArrayMap<String, UserTypeDetails.Builder> builders = new ArrayMap<>();
        builders.put(userTypeAosp1, new UserTypeDetails.Builder()
@@ -395,6 +398,7 @@ public class UserManagerServiceUserTypeTest {
        assertEquals(1, aospType.getDefaultUserPropertiesReference()
                .getCrossProfileContentSharingStrategy());
        assertEquals(36, aospType.getDefaultUserPropertiesReference().getProfileApiVisibility());
        assertFalse(aospType.getDefaultUserPropertiesReference().areItemsRestrictedOnHomeScreen());

        // userTypeAosp2 should be modified.
        aospType = builders.get(userTypeAosp2).createUserTypeDetails();
@@ -452,6 +456,7 @@ public class UserManagerServiceUserTypeTest {
        assertEquals(0, aospType.getDefaultUserPropertiesReference()
                .getCrossProfileContentSharingStrategy());
        assertEquals(36, aospType.getDefaultUserPropertiesReference().getProfileApiVisibility());
        assertTrue(aospType.getDefaultUserPropertiesReference().areItemsRestrictedOnHomeScreen());

        // userTypeOem1 should be created.
        UserTypeDetails.Builder customType = builders.get(userTypeOem1);
Loading