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

Commit 4d9bf3a0 authored by Alex Johnston's avatar Alex Johnston
Browse files

Remove device ownership text in quick settings

* On an org-owned device with a managed profile,
  quick settings has a tappable security footer
  that shows privacy disclosures.
* The footer should be untappable if there
  is no policy applied by the admin that
  requires a disclosure (e.g. network logging).
* The device ownership text will no longer be
  shown for org-owned devices.

Manual testing steps
* Set up org-owned device with managed profile.
* Verify QS footer is visible but untappable.
* Enable network logging.
* Verify QS footer is visible and tappable.
* Verify device ownership text is no longer shown.
* Verify behaviour is unchanged for device owner
  and profile owner.

Bug: 186196610
Test: Manual testing
      atest QSSecurityFooterTest
Change-Id: I0df6dc69dc249544d596375f7cd364d8a4080230
parent 22f83b56
Loading
Loading
Loading
Loading
+15 −19
Original line number Diff line number Diff line
@@ -190,6 +190,16 @@ class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListen
                || vpnName != null || vpnNameWorkProfile != null
                || isProfileOwnerOfOrganizationOwnedDevice || isParentalControlsEnabled
                || (hasWorkProfile && isNetworkLoggingEnabled);
        // Update the view to be untappable if the device is an organization-owned device with a
        // managed profile and there is no policy set which requires a privacy disclosure.
        if (mIsVisible && isProfileOwnerOfOrganizationOwnedDevice && !isNetworkLoggingEnabled
                && !hasCACertsInWorkProfile && vpnNameWorkProfile == null) {
            mRootView.setClickable(false);
            mRootView.findViewById(R.id.footer_icon).setVisibility(View.GONE);
        } else {
            mRootView.setClickable(true);
            mRootView.findViewById(R.id.footer_icon).setVisibility(View.VISIBLE);
        }
        // Update the string
        mFooterTextContent = getFooterText(isDeviceManaged, hasWorkProfile,
                hasCACerts, hasCACertsInWorkProfile, isNetworkLoggingEnabled, vpnName,
@@ -345,20 +355,15 @@ class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListen

    private View createOrganizationDialogView() {
        final boolean isDeviceManaged = mSecurityController.isDeviceManaged();
        boolean isProfileOwnerOfOrganizationOwnedDevice =
                mSecurityController.isProfileOwnerOfOrganizationOwnedDevice();
        final boolean hasWorkProfile = mSecurityController.hasWorkProfile();
        final CharSequence deviceOwnerOrganization =
                mSecurityController.getDeviceOwnerOrganizationName();
        final CharSequence workProfileOrganizationName =
                mSecurityController.getWorkProfileOrganizationName();
        final boolean hasCACerts = mSecurityController.hasCACertInCurrentUser();
        final boolean hasCACertsInWorkProfile = mSecurityController.hasCACertInWorkProfile();
        final boolean isNetworkLoggingEnabled = mSecurityController.isNetworkLoggingEnabled();
        final String vpnName = mSecurityController.getPrimaryVpnName();
        final String vpnNameWorkProfile = mSecurityController.getWorkProfileVpnName();


        View dialogView = LayoutInflater.from(mContext)
                .inflate(R.layout.quick_settings_footer_dialog, null, false);

@@ -368,8 +373,7 @@ class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListen
        deviceManagementSubtitle.setText(getManagementTitle(deviceOwnerOrganization));

        CharSequence managementMessage = getManagementMessage(isDeviceManaged,
                deviceOwnerOrganization, isProfileOwnerOfOrganizationOwnedDevice,
                workProfileOrganizationName);
                deviceOwnerOrganization);
        if (managementMessage == null) {
            dialogView.findViewById(R.id.device_management_disclosures).setVisibility(View.GONE);
        } else {
@@ -377,12 +381,8 @@ class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListen
            TextView deviceManagementWarning =
                    (TextView) dialogView.findViewById(R.id.device_management_warning);
            deviceManagementWarning.setText(managementMessage);
            // Don't show the policies button for profile owner of org owned device, because there
            // is no policies settings screen for it
            if (!isProfileOwnerOfOrganizationOwnedDevice) {
            mDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getSettingsButton(), this);
        }
        }

        // ca certificate section
        CharSequence caCertsMessage = getCaCertsMessage(isDeviceManaged, hasCACerts,
@@ -496,12 +496,11 @@ class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListen
    }

    protected CharSequence getManagementMessage(boolean isDeviceManaged,
            CharSequence organizationName, boolean isProfileOwnerOfOrganizationOwnedDevice,
            CharSequence workProfileOrganizationName) {
        if (!isDeviceManaged && !isProfileOwnerOfOrganizationOwnedDevice) {
            CharSequence organizationName) {
        if (!isDeviceManaged) {
            return null;
        }
        if (isDeviceManaged && organizationName != null) {
        if (organizationName != null) {
            if (isFinancedDevice()) {
                return mContext.getString(R.string.monitoring_financed_description_named_management,
                        organizationName, organizationName);
@@ -509,9 +508,6 @@ class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListen
                return mContext.getString(
                        R.string.monitoring_description_named_management, organizationName);
            }
        } else if (isProfileOwnerOfOrganizationOwnedDevice && workProfileOrganizationName != null) {
            return mContext.getString(
                    R.string.monitoring_description_named_management, workProfileOrganizationName);
        }
        return mContext.getString(R.string.monitoring_description_management);
    }
+28 −32
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -188,6 +189,29 @@ public class QSSecurityFooterTest extends SysuiTestCase {
        assertEquals(View.GONE, mRootView.getVisibility());
    }

    @Test
    public void testUntappableView_profileOwnerOfOrgOwnedDevice() {
        when(mSecurityController.isProfileOwnerOfOrganizationOwnedDevice()).thenReturn(true);

        mFooter.refreshState();

        TestableLooper.get(this).processAllMessages();
        assertFalse(mRootView.isClickable());
        assertEquals(View.GONE, mRootView.findViewById(R.id.footer_icon).getVisibility());
    }

    @Test
    public void testTappableView_profileOwnerOfOrgOwnedDevice_networkLoggingEnabled() {
        when(mSecurityController.isProfileOwnerOfOrganizationOwnedDevice()).thenReturn(true);
        when(mSecurityController.isNetworkLoggingEnabled()).thenReturn(true);

        mFooter.refreshState();

        TestableLooper.get(this).processAllMessages();
        assertTrue(mRootView.isClickable());
        assertEquals(View.VISIBLE, mRootView.findViewById(R.id.footer_icon).getVisibility());
    }

    @Test
    public void testNetworkLoggingEnabled_deviceOwner() {
        when(mSecurityController.isDeviceManaged()).thenReturn(true);
@@ -435,10 +459,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
    @Test
    public void testGetManagementMessage_noManagement() {
        assertEquals(null, mFooter.getManagementMessage(
                /* isDeviceManaged= */ false,
                MANAGING_ORGANIZATION,
                /* isProfileOwnerOfOrganizationOwnedDevice= */ false,
                MANAGING_ORGANIZATION));
                /* isDeviceManaged= */ false, MANAGING_ORGANIZATION));
    }

    @Test
@@ -446,16 +467,11 @@ public class QSSecurityFooterTest extends SysuiTestCase {
        assertEquals(mContext.getString(R.string.monitoring_description_named_management,
                                        MANAGING_ORGANIZATION),
                     mFooter.getManagementMessage(
                             /* isDeviceManaged= */ true,
                             MANAGING_ORGANIZATION,
                             /* isProfileOwnerOfOrganizationOwnedDevice= */ false,
                             /* workProfileOrganizationName= */ null));
                             /* isDeviceManaged= */ true, MANAGING_ORGANIZATION));
        assertEquals(mContext.getString(R.string.monitoring_description_management),
                     mFooter.getManagementMessage(
                             /* isDeviceManaged= */ true,
                             /* organizationName= */ null,
                             /* isProfileOwnerOfOrganizationOwnedDevice= */ false,
                             /* workProfileOrganizationName= */ null));
                             /* organizationName= */ null));
    }

    @Test
@@ -467,27 +483,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
        assertEquals(mContext.getString(R.string.monitoring_financed_description_named_management,
                MANAGING_ORGANIZATION, MANAGING_ORGANIZATION),
                mFooter.getManagementMessage(
                        /* isDeviceManaged= */ true,
                        MANAGING_ORGANIZATION,
                        /* isProfileOwnerOfOrganizationOwnedDevice= */ false,
                        /* workProfileOrganizationName= */ null));
    }

    @Test
    public void testGetManagementMessage_profileOwnerOfOrganizationOwnedDevice() {
        assertEquals(mContext.getString(R.string.monitoring_description_named_management,
                MANAGING_ORGANIZATION),
                mFooter.getManagementMessage(
                        /* isDeviceManaged= */ false,
                        /* organizationName= */ null,
                        /* isProfileOwnerOfOrganizationOwnedDevice= */ true,
                        MANAGING_ORGANIZATION));
        assertEquals(mContext.getString(R.string.monitoring_description_management),
                mFooter.getManagementMessage(
                        /* isDeviceManaged= */ false,
                        /* organizationName= */ null,
                        /* isProfileOwnerOfOrganizationOwnedDevice= */ true,
                        /* workProfileOrganizationName= */ null));
                        /* isDeviceManaged= */ true, MANAGING_ORGANIZATION));
    }

    @Test