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

Commit 7822050c authored by Jigar Thakkar's avatar Jigar Thakkar Committed by Android (Google) Code Review
Browse files

Merge "Disallow bluetooth sharing by default for private profiles" into main

parents 20964d78 c12a4cb7
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -705,7 +705,7 @@ public class UserManager {
     * {@link android.Manifest.permission#MANAGE_DEVICE_POLICY_BLUETOOTH}
     * {@link android.Manifest.permission#MANAGE_DEVICE_POLICY_BLUETOOTH}
     * can set this restriction using the DevicePolicyManager APIs mentioned below.
     * 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
     * <p>When a device upgrades to {@link android.os.Build.VERSION_CODES#O}, the system sets it
     * for all existing managed profiles.
     * for all existing managed profiles.
+8 −1
Original line number Original line Diff line number Diff line
@@ -306,7 +306,7 @@ public final class UserTypeFactory {
                        R.color.black)
                        R.color.black)
                .setDarkThemeBadgeColors(
                .setDarkThemeBadgeColors(
                        R.color.white)
                        R.color.white)
                .setDefaultRestrictions(getDefaultProfileRestrictions())
                .setDefaultRestrictions(getDefaultPrivateProfileRestrictions())
                .setDefaultCrossProfileIntentFilters(getDefaultPrivateCrossProfileIntentFilter())
                .setDefaultCrossProfileIntentFilters(getDefaultPrivateCrossProfileIntentFilter())
                .setDefaultUserProperties(new UserProperties.Builder()
                .setDefaultUserProperties(new UserProperties.Builder()
                        .setStartWithParent(true)
                        .setStartWithParent(true)
@@ -430,6 +430,13 @@ public final class UserTypeFactory {
        return restrictions;
        return restrictions;
    }
    }


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

    private static Bundle getDefaultManagedProfileSecureSettings() {
    private static Bundle getDefaultManagedProfileSecureSettings() {
        // Only add String values to the bundle, settings are written as Strings eventually
        // Only add String values to the bundle, settings are written as Strings eventually
        final Bundle settings = new Bundle();
        final Bundle settings = new Bundle();
+24 −0
Original line number Original line 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
    @MediumTest
    @Test
    @Test
    public void testAddRestrictedProfile() throws Exception {
    public void testAddRestrictedProfile() throws Exception {