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

Commit 61499a25 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere Committed by Automerger Merge Worker
Browse files

Extract QSSecurityFooterUtils out of QSSecurityFooter am: d7d2de53

parents 24a02e8a d7d2de53
Loading
Loading
Loading
Loading
+12 −737

File changed.

Preview size limit exceeded, changes collapsed.

+792 −0

File added.

Preview size limit exceeded, changes collapsed.

+44 −41
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
    private TextView mFooterText;
    private TestableImageView mPrimaryFooterIcon;
    private QSSecurityFooter mFooter;
    private QSSecurityFooterUtils mFooterUtils;
    @Mock
    private SecurityController mSecurityController;
    @Mock
@@ -118,13 +119,15 @@ public class QSSecurityFooterTest extends SysuiTestCase {
        MockitoAnnotations.initMocks(this);
        mTestableLooper = TestableLooper.get(this);
        Looper looper = mTestableLooper.getLooper();
        Handler mainHandler = new Handler(looper);
        when(mUserTracker.getUserInfo()).thenReturn(mock(UserInfo.class));
        mRootView = (ViewGroup) new LayoutInflaterBuilder(mContext)
                .replace("ImageView", TestableImageView.class)
                .build().inflate(R.layout.quick_settings_security_footer, null, false);
        mFooter = new QSSecurityFooter(mRootView, mUserTracker, new Handler(looper),
                mActivityStarter, mSecurityController, mDialogLaunchAnimator, looper,
                mBroadcastDispatcher);
        mFooterUtils = new QSSecurityFooterUtils(getContext(), mUserTracker, mainHandler,
                mActivityStarter, mSecurityController, looper, mDialogLaunchAnimator);
        mFooter = new QSSecurityFooter(mRootView, mainHandler, mSecurityController, looper,
                mBroadcastDispatcher, mFooterUtils);
        mFooterText = mRootView.findViewById(R.id.footer_text);
        mPrimaryFooterIcon = mRootView.findViewById(R.id.primary_footer_icon);

@@ -520,7 +523,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
        when(mSecurityController.isDeviceManaged()).thenReturn(true);

        assertEquals(mContext.getString(R.string.monitoring_title_device_owned),
                mFooter.getManagementTitle(MANAGING_ORGANIZATION));
                mFooterUtils.getManagementTitle(MANAGING_ORGANIZATION));
    }

    @Test
@@ -531,12 +534,12 @@ public class QSSecurityFooterTest extends SysuiTestCase {

        assertEquals(mContext.getString(R.string.monitoring_title_financed_device,
                MANAGING_ORGANIZATION),
                mFooter.getManagementTitle(MANAGING_ORGANIZATION));
                mFooterUtils.getManagementTitle(MANAGING_ORGANIZATION));
    }

    @Test
    public void testGetManagementMessage_noManagement() {
        assertEquals(null, mFooter.getManagementMessage(
        assertEquals(null, mFooterUtils.getManagementMessage(
                /* isDeviceManaged= */ false, MANAGING_ORGANIZATION));
    }

@@ -544,10 +547,10 @@ public class QSSecurityFooterTest extends SysuiTestCase {
    public void testGetManagementMessage_deviceOwner() {
        assertEquals(mContext.getString(R.string.monitoring_description_named_management,
                                        MANAGING_ORGANIZATION),
                     mFooter.getManagementMessage(
                mFooterUtils.getManagementMessage(
                             /* isDeviceManaged= */ true, MANAGING_ORGANIZATION));
        assertEquals(mContext.getString(R.string.monitoring_description_management),
                     mFooter.getManagementMessage(
                mFooterUtils.getManagementMessage(
                             /* isDeviceManaged= */ true,
                             /* organizationName= */ null));
    }
@@ -560,68 +563,68 @@ public class QSSecurityFooterTest extends SysuiTestCase {

        assertEquals(mContext.getString(R.string.monitoring_financed_description_named_management,
                MANAGING_ORGANIZATION, MANAGING_ORGANIZATION),
                mFooter.getManagementMessage(
                mFooterUtils.getManagementMessage(
                        /* isDeviceManaged= */ true, MANAGING_ORGANIZATION));
    }

    @Test
    public void testGetCaCertsMessage() {
        assertEquals(null, mFooter.getCaCertsMessage(true, false, false));
        assertEquals(null, mFooter.getCaCertsMessage(false, false, false));
        assertEquals(null, mFooterUtils.getCaCertsMessage(true, false, false));
        assertEquals(null, mFooterUtils.getCaCertsMessage(false, false, false));
        assertEquals(mContext.getString(R.string.monitoring_description_management_ca_certificate),
                     mFooter.getCaCertsMessage(true, true, true));
                mFooterUtils.getCaCertsMessage(true, true, true));
        assertEquals(mContext.getString(R.string.monitoring_description_management_ca_certificate),
                     mFooter.getCaCertsMessage(true, false, true));
                mFooterUtils.getCaCertsMessage(true, false, true));
        assertEquals(mContext.getString(
                         R.string.monitoring_description_managed_profile_ca_certificate),
                     mFooter.getCaCertsMessage(false, false, true));
                mFooterUtils.getCaCertsMessage(false, false, true));
        assertEquals(mContext.getString(
                         R.string.monitoring_description_ca_certificate),
                     mFooter.getCaCertsMessage(false, true, false));
                mFooterUtils.getCaCertsMessage(false, true, false));
    }

    @Test
    public void testGetNetworkLoggingMessage() {
        // Test network logging message on a device with a device owner.
        // Network traffic may be monitored on the device.
        assertEquals(null, mFooter.getNetworkLoggingMessage(true, false));
        assertEquals(null, mFooterUtils.getNetworkLoggingMessage(true, false));
        assertEquals(mContext.getString(R.string.monitoring_description_management_network_logging),
                mFooter.getNetworkLoggingMessage(true, true));
                mFooterUtils.getNetworkLoggingMessage(true, true));

        // Test network logging message on a device with a managed profile owner
        // Network traffic may be monitored on the work profile.
        assertEquals(null, mFooter.getNetworkLoggingMessage(false, false));
        assertEquals(null, mFooterUtils.getNetworkLoggingMessage(false, false));
        assertEquals(
                mContext.getString(R.string.monitoring_description_managed_profile_network_logging),
                mFooter.getNetworkLoggingMessage(false, true));
                mFooterUtils.getNetworkLoggingMessage(false, true));
    }

    @Test
    public void testGetVpnMessage() {
        assertEquals(null, mFooter.getVpnMessage(true, true, null, null));
        assertEquals(null, mFooterUtils.getVpnMessage(true, true, null, null));
        assertEquals(addLink(mContext.getString(R.string.monitoring_description_two_named_vpns,
                                 VPN_PACKAGE, VPN_PACKAGE_2)),
                     mFooter.getVpnMessage(true, true, VPN_PACKAGE, VPN_PACKAGE_2));
                mFooterUtils.getVpnMessage(true, true, VPN_PACKAGE, VPN_PACKAGE_2));
        assertEquals(addLink(mContext.getString(R.string.monitoring_description_two_named_vpns,
                                 VPN_PACKAGE, VPN_PACKAGE_2)),
                     mFooter.getVpnMessage(false, true, VPN_PACKAGE, VPN_PACKAGE_2));
                mFooterUtils.getVpnMessage(false, true, VPN_PACKAGE, VPN_PACKAGE_2));
        assertEquals(addLink(mContext.getString(R.string.monitoring_description_named_vpn,
                                 VPN_PACKAGE)),
                     mFooter.getVpnMessage(true, false, VPN_PACKAGE, null));
                mFooterUtils.getVpnMessage(true, false, VPN_PACKAGE, null));
        assertEquals(addLink(mContext.getString(R.string.monitoring_description_named_vpn,
                                 VPN_PACKAGE)),
                     mFooter.getVpnMessage(false, false, VPN_PACKAGE, null));
                mFooterUtils.getVpnMessage(false, false, VPN_PACKAGE, null));
        assertEquals(addLink(mContext.getString(R.string.monitoring_description_named_vpn,
                                 VPN_PACKAGE_2)),
                     mFooter.getVpnMessage(true, true, null, VPN_PACKAGE_2));
                mFooterUtils.getVpnMessage(true, true, null, VPN_PACKAGE_2));
        assertEquals(addLink(mContext.getString(
                                 R.string.monitoring_description_managed_profile_named_vpn,
                                 VPN_PACKAGE_2)),
                     mFooter.getVpnMessage(false, true, null, VPN_PACKAGE_2));
                mFooterUtils.getVpnMessage(false, true, null, VPN_PACKAGE_2));
        assertEquals(addLink(mContext.getString(
                                 R.string.monitoring_description_personal_profile_named_vpn,
                                 VPN_PACKAGE)),
                     mFooter.getVpnMessage(false, true, VPN_PACKAGE, null));
                mFooterUtils.getVpnMessage(false, true, VPN_PACKAGE, null));
    }

    @Test
@@ -631,19 +634,19 @@ public class QSSecurityFooterTest extends SysuiTestCase {

        // Device Management subtitle should be shown when there is Device Management section only
        // Other sections visibility will be set somewhere else so it will not be tested here
        mFooter.configSubtitleVisibility(true, false, false, false, view);
        mFooterUtils.configSubtitleVisibility(true, false, false, false, view);
        assertEquals(View.VISIBLE,
                view.findViewById(R.id.device_management_subtitle).getVisibility());

        // If there are multiple sections, all subtitles should be shown
        mFooter.configSubtitleVisibility(true, true, false, false, view);
        mFooterUtils.configSubtitleVisibility(true, true, false, false, view);
        assertEquals(View.VISIBLE,
                view.findViewById(R.id.device_management_subtitle).getVisibility());
        assertEquals(View.VISIBLE,
                view.findViewById(R.id.ca_certs_subtitle).getVisibility());

        // If there are multiple sections, all subtitles should be shown
        mFooter.configSubtitleVisibility(true, true, true, true, view);
        mFooterUtils.configSubtitleVisibility(true, true, true, true, view);
        assertEquals(View.VISIBLE,
                view.findViewById(R.id.device_management_subtitle).getVisibility());
        assertEquals(View.VISIBLE,
@@ -655,7 +658,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {

        // If there are multiple sections, all subtitles should be shown, event if there is no
        // Device Management section
        mFooter.configSubtitleVisibility(false, true, true, true, view);
        mFooterUtils.configSubtitleVisibility(false, true, true, true, view);
        assertEquals(View.VISIBLE,
                view.findViewById(R.id.ca_certs_subtitle).getVisibility());
        assertEquals(View.VISIBLE,
@@ -664,13 +667,13 @@ public class QSSecurityFooterTest extends SysuiTestCase {
                view.findViewById(R.id.vpn_subtitle).getVisibility());

        // If there is only 1 section, the title should be hidden
        mFooter.configSubtitleVisibility(false, true, false, false, view);
        mFooterUtils.configSubtitleVisibility(false, true, false, false, view);
        assertEquals(View.GONE,
                view.findViewById(R.id.ca_certs_subtitle).getVisibility());
        mFooter.configSubtitleVisibility(false, false, true, false, view);
        mFooterUtils.configSubtitleVisibility(false, false, true, false, view);
        assertEquals(View.GONE,
                view.findViewById(R.id.network_logging_subtitle).getVisibility());
        mFooter.configSubtitleVisibility(false, false, false, true, view);
        mFooterUtils.configSubtitleVisibility(false, false, false, true, view);
        assertEquals(View.GONE,
                view.findViewById(R.id.vpn_subtitle).getVisibility());
    }
@@ -722,7 +725,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
        when(mSecurityController.isParentalControlsEnabled()).thenReturn(true);
        when(mSecurityController.getLabel(any())).thenReturn(PARENTAL_CONTROLS_LABEL);

        View view = mFooter.createDialogView();
        View view = mFooterUtils.createDialogView();
        TextView textView = (TextView) view.findViewById(R.id.parental_controls_title);
        assertEquals(PARENTAL_CONTROLS_LABEL, textView.getText());
    }
@@ -745,7 +748,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
        when(mSecurityController.getDeviceOwnerType(DEVICE_OWNER_COMPONENT))
                .thenReturn(DEVICE_OWNER_TYPE_FINANCED);

        View view = mFooter.createDialogView();
        View view = mFooterUtils.createDialogView();

        TextView managementSubtitle = view.findViewById(R.id.device_management_subtitle);
        assertEquals(View.VISIBLE, managementSubtitle.getVisibility());
@@ -756,7 +759,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
        assertEquals(mContext.getString(R.string.monitoring_financed_description_named_management,
                MANAGING_ORGANIZATION, MANAGING_ORGANIZATION), managementMessage.getText());
        assertEquals(mContext.getString(R.string.monitoring_button_view_policies),
                mFooter.getSettingsButton());
                mFooterUtils.getSettingsButton());
    }

    @Test
@@ -776,7 +779,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
        AlertDialog dialog = dialogCaptor.getValue();
        dialog.create();

        assertEquals(mFooter.getSettingsButton(),
        assertEquals(mFooterUtils.getSettingsButton(),
                dialog.getButton(DialogInterface.BUTTON_NEGATIVE).getText());

        dialog.dismiss();
@@ -819,8 +822,8 @@ public class QSSecurityFooterTest extends SysuiTestCase {
                new Intent(DevicePolicyManager.ACTION_SHOW_DEVICE_MONITORING_DIALOG));
        mTestableLooper.processAllMessages();

        assertTrue(mFooter.getDialog().isShowing());
        mFooter.getDialog().dismiss();
        assertTrue(mFooterUtils.getDialog().isShowing());
        mFooterUtils.getDialog().dismiss();
    }

    private CharSequence addLink(CharSequence description) {
@@ -828,7 +831,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
        message.append(description);
        message.append(mContext.getString(R.string.monitoring_description_vpn_settings_separator));
        message.append(mContext.getString(R.string.monitoring_description_vpn_settings),
                mFooter.new VpnSpan(), 0);
                mFooterUtils.new VpnSpan(), 0);
        return message;
    }
}