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

Commit c12a4cb7 authored by Jigar Thakkar's avatar Jigar Thakkar
Browse files

Disallow bluetooth sharing by default for private profiles

This change adds the user restriction DISALLOW_BLUETOOTH_SHARING to the
list of default restrictions applied on private profile creation. This
will result in the "bluetooth" option not showing up in the "private"
tab of the sharesheet. Please note that users would still be able to use
the share via bluetooth option in the "primary" tab in sharesheet.

Test: atest UserManagerTest#testDefaultUserRestrictionsForPrivateProfile
Bug: 296357858
Change-Id: Idf07014a11690576d220d2599bb6a1f663a41789
parent 8fd912f6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -705,7 +705,7 @@ public class UserManager {
     * {@link android.Manifest.permission#MANAGE_DEVICE_POLICY_BLUETOOTH}
     * can set this restriction using the DevicePolicyManager APIs mentioned below.
     *
     * <p>Default is <code>true</code> for managed profiles and false otherwise.
     * <p>Default is <code>true</code> for managed and private profiles, false otherwise.
     *
     * <p>When a device upgrades to {@link android.os.Build.VERSION_CODES#O}, the system sets it
     * for all existing managed profiles.
+8 −1
Original line number Diff line number Diff line
@@ -306,7 +306,7 @@ public final class UserTypeFactory {
                        R.color.black)
                .setDarkThemeBadgeColors(
                        R.color.white)
                .setDefaultRestrictions(getDefaultProfileRestrictions())
                .setDefaultRestrictions(getDefaultPrivateProfileRestrictions())
                .setDefaultCrossProfileIntentFilters(getDefaultPrivateCrossProfileIntentFilter())
                .setDefaultUserProperties(new UserProperties.Builder()
                        .setStartWithParent(true)
@@ -430,6 +430,13 @@ public final class UserTypeFactory {
        return restrictions;
    }

    @VisibleForTesting
    static Bundle getDefaultPrivateProfileRestrictions() {
        final Bundle restrictions = getDefaultProfileRestrictions();
        restrictions.putBoolean(UserManager.DISALLOW_BLUETOOTH_SHARING, true);
        return restrictions;
    }

    private static Bundle getDefaultManagedProfileSecureSettings() {
        // Only add String values to the bundle, settings are written as Strings eventually
        final Bundle settings = new Bundle();
+24 −0
Original line number Diff line number Diff line
@@ -1254,6 +1254,30 @@ public final class UserManagerTest {
        }
    }

    @MediumTest
    @Test
    public void testDefaultUserRestrictionsForPrivateProfile() {
        assumeTrue(mUserManager.canAddPrivateProfile());
        final int currentUserId = ActivityManager.getCurrentUser();
        UserInfo privateProfileInfo = null;
        try {
            privateProfileInfo = createProfileForUser("Private",
                    UserManager.USER_TYPE_PROFILE_PRIVATE, currentUserId);
            assertThat(privateProfileInfo).isNotNull();
        } catch (Exception e) {
            fail("Creation of private profile failed due to " + e.getMessage());
        }
        assertDefaultPrivateProfileRestrictions(privateProfileInfo.getUserHandle());
    }

    private void assertDefaultPrivateProfileRestrictions(UserHandle userHandle) {
        Bundle defaultPrivateProfileRestrictions =
                UserTypeFactory.getDefaultPrivateProfileRestrictions();
        for (String restriction : defaultPrivateProfileRestrictions.keySet()) {
            assertThat(mUserManager.hasUserRestrictionForUser(restriction, userHandle)).isTrue();
        }
    }

    @MediumTest
    @Test
    public void testAddRestrictedProfile() throws Exception {