diff options
5 files changed, 268 insertions, 207 deletions
diff --git a/packages/SystemUI/res/layout/quick_settings_footer.xml b/packages/SystemUI/res/layout/quick_settings_footer.xml index bb1b288cf3bf..846c5386dd06 100644 --- a/packages/SystemUI/res/layout/quick_settings_footer.xml +++ b/packages/SystemUI/res/layout/quick_settings_footer.xml @@ -23,7 +23,7 @@ android:paddingStart="@dimen/qs_footer_padding_start" android:paddingEnd="@dimen/qs_footer_padding_end" android:gravity="center_vertical" - android:background="?android:attr/colorPrimaryDark" > + android:background="?android:attr/colorPrimary" > <TextView android:id="@+id/footer_text" @@ -39,6 +39,7 @@ android:layout_width="@dimen/qs_footer_icon_size" android:layout_height="@dimen/qs_footer_icon_size" android:contentDescription="@null" - android:src="@drawable/ic_info_outline" /> + android:src="@drawable/ic_info_outline" + android:tint="?android:attr/textColorSecondary"/> </LinearLayout> diff --git a/packages/SystemUI/res/layout/quick_settings_footer_dialog.xml b/packages/SystemUI/res/layout/quick_settings_footer_dialog.xml index 397fbf10dc81..307b5389521a 100644 --- a/packages/SystemUI/res/layout/quick_settings_footer_dialog.xml +++ b/packages/SystemUI/res/layout/quick_settings_footer_dialog.xml @@ -27,90 +27,105 @@ android:paddingTop="?android:attr/dialogPreferredPadding" android:paddingRight="?android:attr/dialogPreferredPadding" android:paddingLeft="?android:attr/dialogPreferredPadding" - android:paddingBottom="?android:attr/dialogPreferredPadding" android:orientation="vertical"> - <TextView - android:id="@+id/device_owner_warning" + <LinearLayout + android:id="@+id/device_management_disclosures" android:layout_width="match_parent" android:layout_height="wrap_content" - style="@android:style/TextAppearance.Material.Subhead" - android:textColor="?android:attr/textColorPrimaryInverse" - /> + android:paddingBottom="?android:attr/dialogPreferredPadding" + android:orientation="vertical"> + <TextView + android:id="@+id/device_management_subtitle" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/monitoring_title_device_owned" + style="@android:style/TextAppearance.Material.Title" + android:textColor="?android:attr/textColorPrimary" + android:paddingBottom="@dimen/qs_footer_dialog_subtitle_padding" + /> + <TextView + android:id="@+id/device_management_warning" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@null" + style="@android:style/TextAppearance.Material.Subhead" + android:textColor="?android:attr/textColorPrimary" + /> + </LinearLayout> + <LinearLayout + android:id="@+id/ca_certs_disclosures" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal"> - <ImageView - android:id="@+id/vpn_icon" - android:layout_width="@dimen/qs_footer_dialog_icon_size" + android:paddingBottom="?android:attr/dialogPreferredPadding" + android:orientation="vertical"> + <TextView + android:id="@+id/ca_certs_subtitle" + android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingTop="?android:attr/dialogPreferredPadding" - android:layout_marginStart="@dimen/qs_footer_dialog_icon_margin" - android:layout_marginEnd="@dimen/qs_footer_dialog_icon_margin" - android:scaleType="fitCenter" - android:src="@drawable/ic_qs_vpn" - android:tint="?android:attr/textColorPrimaryInverse" - android:adjustViewBounds="true"/> - <LinearLayout + android:text="@string/monitoring_subtitle_ca_certificate" + style="@android:style/TextAppearance.Material.Title" + android:textColor="?android:attr/textColorPrimary" + android:paddingBottom="@dimen/qs_footer_dialog_subtitle_padding" + /> + <TextView + android:id="@+id/ca_certs_warning" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="vertical"> - <TextView - android:id="@+id/vpn_subtitle" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:paddingTop="?android:attr/dialogPreferredPadding" - android:text="@string/monitoring_subtitle_vpn" - style="@android:style/TextAppearance.Material.Title" - android:textColor="?android:attr/textColorPrimaryInverse" - /> - <TextView - android:id="@+id/vpn_warning" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:text="@null" - style="@android:style/TextAppearance.Material.Subhead" - android:textColor="?android:attr/textColorPrimaryInverse" - /> - </LinearLayout> + android:text="@null" + style="@android:style/TextAppearance.Material.Subhead" + android:textColor="?android:attr/textColorPrimary" + /> </LinearLayout> + <LinearLayout + android:id="@+id/network_logging_disclosures" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal"> - <ImageView - android:id="@+id/network_logging_icon" - android:layout_width="@dimen/qs_footer_dialog_icon_size" + android:paddingBottom="?android:attr/dialogPreferredPadding" + android:orientation="vertical"> + <TextView + android:id="@+id/network_logging_subtitle" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/monitoring_subtitle_network_logging" + style="@android:style/TextAppearance.Material.Title" + android:textColor="?android:attr/textColorPrimary" + android:paddingBottom="@dimen/qs_footer_dialog_subtitle_padding" + /> + <TextView + android:id="@+id/network_logging_warning" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@null" + style="@android:style/TextAppearance.Material.Subhead" + android:textColor="?android:attr/textColorPrimary" + /> + </LinearLayout> + + <LinearLayout + android:id="@+id/vpn_disclosures" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingBottom="?android:attr/dialogPreferredPadding" + android:orientation="vertical"> + <TextView + android:id="@+id/vpn_subtitle" + android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingTop="?android:attr/dialogPreferredPadding" - android:layout_marginStart="@dimen/qs_footer_dialog_icon_margin" - android:layout_marginEnd="@dimen/qs_footer_dialog_icon_margin" - android:scaleType="fitCenter" - android:src="@drawable/ic_qs_network_logging" - android:tint="?android:attr/textColorPrimaryInverse" - android:adjustViewBounds="true"/> - <LinearLayout + android:text="@string/monitoring_subtitle_vpn" + style="@android:style/TextAppearance.Material.Title" + android:textColor="?android:attr/textColorPrimary" + android:paddingBottom="@dimen/qs_footer_dialog_subtitle_padding" + /> + <TextView + android:id="@+id/vpn_warning" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="vertical"> - <TextView - android:id="@+id/network_logging_subtitle" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:paddingTop="?android:attr/dialogPreferredPadding" - android:text="@string/monitoring_subtitle_network_logging" - style="@android:style/TextAppearance.Material.Title" - android:textColor="?android:attr/textColorPrimaryInverse" - /> - <TextView - android:id="@+id/network_logging_warning" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:text="@string/monitoring_description_network_logging" - style="@android:style/TextAppearance.Material.Subhead" - android:textColor="?android:attr/textColorPrimaryInverse" - /> - </LinearLayout> + android:text="@null" + style="@android:style/TextAppearance.Material.Subhead" + android:textColor="?android:attr/textColorPrimary" + /> </LinearLayout> </LinearLayout> </ScrollView> diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 4edadea38a93..cdb5af92c0c8 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -282,6 +282,8 @@ <dimen name="qs_footer_dialog_icon_size">24sp</dimen> <!-- Left and right margin of the icons --> <dimen name="qs_footer_dialog_icon_margin">8sp</dimen> + <!-- Padding between subtitles and the following text in the QSFooter dialog --> + <dimen name="qs_footer_dialog_subtitle_padding">20dp</dimen> <!-- Zen mode panel: condition item button padding --> <dimen name="zen_mode_condition_detail_button_padding">8dp</dimen> diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java b/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java index 51c6ad88a2af..d434f2f7032d 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java @@ -31,6 +31,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.View.OnClickListener; +import android.view.Window; import android.widget.ImageView; import android.widget.TextView; @@ -224,117 +225,152 @@ public class QSSecurityFooter implements OnClickListener, DialogInterface.OnClic @Override public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_NEGATIVE) { - final Intent settingsIntent = new Intent(ACTION_VPN_SETTINGS); - mActivityStarter.postStartActivityDismissingKeyguard(settingsIntent, 0); + final Intent intent = new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS); + mDialog.dismiss(); + mActivityStarter.postStartActivityDismissingKeyguard(intent, 0); } } private void createDialog() { - final String deviceOwnerPackage = mSecurityController.getDeviceOwnerName(); - final String profileOwnerPackage = mSecurityController.getProfileOwnerName(); - final boolean isNetworkLoggingEnabled = mSecurityController.isNetworkLoggingEnabled(); - final String primaryVpn = mSecurityController.getPrimaryVpnName(); - final String profileVpn = mSecurityController.getWorkProfileVpnName(); + final boolean isDeviceManaged = mSecurityController.isDeviceManaged(); + final boolean hasWorkProfile = mSecurityController.hasWorkProfile(); final CharSequence deviceOwnerOrganization = mSecurityController.getDeviceOwnerOrganizationName(); - boolean hasProfileOwner = mSecurityController.hasProfileOwner(); + 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(); mDialog = new SystemUIDialog(mContext); - mDialog.setTitle(getTitle(deviceOwnerPackage)); - CharSequence msg = getMessage(deviceOwnerPackage, profileOwnerPackage, primaryVpn, - profileVpn, deviceOwnerOrganization, hasProfileOwner); - if (deviceOwnerPackage == null) { - mDialog.setMessage(msg); - if (mSecurityController.isVpnEnabled() && !mSecurityController.isVpnRestricted()) { - mDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getSettingsButton(), this); - } + mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + View dialogView = LayoutInflater.from(mContext) + .inflate(R.layout.quick_settings_footer_dialog, null, false); + mDialog.setView(dialogView); + mDialog.setButton(DialogInterface.BUTTON_POSITIVE, getPositiveButton(), this); + + // device management section + CharSequence managementMessage = getManagementMessage(isDeviceManaged, + deviceOwnerOrganization); + if (managementMessage == null) { + dialogView.findViewById(R.id.device_management_disclosures).setVisibility(View.GONE); } else { - View dialogView = LayoutInflater.from(mContext) - .inflate(R.layout.quick_settings_footer_dialog, null, false); - mDialog.setView(dialogView); - TextView deviceOwnerWarning = - (TextView) dialogView.findViewById(R.id.device_owner_warning); - deviceOwnerWarning.setText(msg); - // Make the link "learn more" clickable. - deviceOwnerWarning.setMovementMethod(new LinkMovementMethod()); - if (primaryVpn == null) { - dialogView.findViewById(R.id.vpn_icon).setVisibility(View.GONE); - dialogView.findViewById(R.id.vpn_subtitle).setVisibility(View.GONE); - dialogView.findViewById(R.id.vpn_warning).setVisibility(View.GONE); - } else { - final SpannableStringBuilder message = new SpannableStringBuilder(); - message.append(mContext.getString(R.string.monitoring_description_do_body_vpn, - primaryVpn)); - if (!mSecurityController.isVpnRestricted()) { - message.append(mContext.getString( - R.string.monitoring_description_vpn_settings_separator)); - message.append(mContext.getString(R.string.monitoring_description_vpn_settings), - new VpnSpan(), 0); - } + dialogView.findViewById(R.id.device_management_disclosures).setVisibility(View.VISIBLE); + TextView deviceManagementWarning = + (TextView) dialogView.findViewById(R.id.device_management_warning); + deviceManagementWarning.setText(managementMessage); + mDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getSettingsButton(), this); + } - TextView vpnWarning = (TextView) dialogView.findViewById(R.id.vpn_warning); - vpnWarning.setText(message); - // Make the link "Open VPN Settings" clickable. - vpnWarning.setMovementMethod(new LinkMovementMethod()); - } - if (!isNetworkLoggingEnabled) { - dialogView.findViewById(R.id.network_logging_icon).setVisibility(View.GONE); - dialogView.findViewById(R.id.network_logging_subtitle).setVisibility(View.GONE); - dialogView.findViewById(R.id.network_logging_warning).setVisibility(View.GONE); - } + // ca certificate section + CharSequence caCertsMessage = getCaCertsMessage(isDeviceManaged, hasCACerts, + hasCACertsInWorkProfile); + if (caCertsMessage == null) { + dialogView.findViewById(R.id.ca_certs_disclosures).setVisibility(View.GONE); + } else { + dialogView.findViewById(R.id.ca_certs_disclosures).setVisibility(View.VISIBLE); + TextView caCertsWarning = (TextView) dialogView.findViewById(R.id.ca_certs_warning); + caCertsWarning.setText(caCertsMessage); + // Make "Open trusted credentials"-link clickable + caCertsWarning.setMovementMethod(new LinkMovementMethod()); + } + + // network logging section + CharSequence networkLoggingMessage = getNetworkLoggingMessage(isNetworkLoggingEnabled); + if (networkLoggingMessage == null) { + dialogView.findViewById(R.id.network_logging_disclosures).setVisibility(View.GONE); + } else { + dialogView.findViewById(R.id.network_logging_disclosures).setVisibility(View.VISIBLE); + TextView networkLoggingWarning = + (TextView) dialogView.findViewById(R.id.network_logging_warning); + networkLoggingWarning.setText(networkLoggingMessage); + } + + // vpn section + CharSequence vpnMessage = getVpnMessage(isDeviceManaged, hasWorkProfile, vpnName, + vpnNameWorkProfile); + if (vpnMessage == null) { + dialogView.findViewById(R.id.vpn_disclosures).setVisibility(View.GONE); + } else { + dialogView.findViewById(R.id.vpn_disclosures).setVisibility(View.VISIBLE); + TextView vpnWarning = (TextView) dialogView.findViewById(R.id.vpn_warning); + vpnWarning.setText(vpnMessage); + // Make "Open VPN Settings"-link clickable + vpnWarning.setMovementMethod(new LinkMovementMethod()); } - mDialog.setButton(DialogInterface.BUTTON_POSITIVE, getPositiveButton(), this); mDialog.show(); - mDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + mDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT); } private String getSettingsButton() { - return mContext.getString(R.string.status_bar_settings_settings_button); + return mContext.getString(R.string.monitoring_button_view_policies); } private String getPositiveButton() { return mContext.getString(R.string.quick_settings_done); } - protected CharSequence getMessage(String deviceOwnerPackage, String profileOwnerPackage, - String primaryVpn, String profileVpn, CharSequence deviceOwnerOrganization, - boolean hasProfileOwner) { - if (deviceOwnerPackage != null) { - final SpannableStringBuilder message = new SpannableStringBuilder(); - if (deviceOwnerOrganization != null) { - message.append(mContext.getString( - R.string.monitoring_description_do_header_with_name, - deviceOwnerOrganization, deviceOwnerPackage)); + protected CharSequence getManagementMessage(boolean isDeviceManaged, + CharSequence organizationName) { + if (!isDeviceManaged) return null; + if (organizationName != null) + return mContext.getString( + R.string.monitoring_description_named_management, organizationName); + return mContext.getString(R.string.monitoring_description_management); + } + + protected CharSequence getCaCertsMessage(boolean isDeviceManaged, boolean hasCACerts, + boolean hasCACertsInWorkProfile) { + if (!(hasCACerts || hasCACertsInWorkProfile)) return null; + if (isDeviceManaged) { + return mContext.getString(R.string.monitoring_description_management_ca_certificate); + } + if (hasCACertsInWorkProfile) { + return mContext.getString( + R.string.monitoring_description_managed_profile_ca_certificate); + } + return mContext.getString(R.string.monitoring_description_ca_certificate); + } + + protected CharSequence getNetworkLoggingMessage(boolean isNetworkLoggingEnabled) { + if (!isNetworkLoggingEnabled) return null; + return mContext.getString(R.string.monitoring_description_management_network_logging); + } + + protected CharSequence getVpnMessage(boolean isDeviceManaged, boolean hasWorkProfile, + String vpnName, String vpnNameWorkProfile) { + if (vpnName == null && vpnNameWorkProfile == null) return null; + final SpannableStringBuilder message = new SpannableStringBuilder(); + if (isDeviceManaged) { + if (vpnName != null && vpnNameWorkProfile != null) { + message.append(mContext.getString(R.string.monitoring_description_two_named_vpns, + vpnName, vpnNameWorkProfile)); } else { - message.append(mContext.getString(R.string.monitoring_description_do_header_generic, - deviceOwnerPackage)); + message.append(mContext.getString(R.string.monitoring_description_named_vpn, + vpnName != null ? vpnName : vpnNameWorkProfile)); } - message.append("\n\n"); - message.append(mContext.getString(R.string.monitoring_description_do_body)); - message.append(mContext.getString( - R.string.monitoring_description_do_learn_more_separator)); - message.append(mContext.getString(R.string.monitoring_description_do_learn_more), - new EnterprisePrivacySpan(), 0); - return message; - } else if (primaryVpn != null) { - if (profileVpn != null) { - return mContext.getString(R.string.monitoring_description_app_personal_work, - profileOwnerPackage, profileVpn, primaryVpn); + } else { + if (vpnName != null && vpnNameWorkProfile != null) { + message.append(mContext.getString(R.string.monitoring_description_two_named_vpns, + vpnName, vpnNameWorkProfile)); + } else if (vpnNameWorkProfile != null) { + message.append(mContext.getString( + R.string.monitoring_description_managed_profile_named_vpn, + vpnNameWorkProfile)); + } else if (hasWorkProfile) { + message.append(mContext.getString( + R.string.monitoring_description_personal_profile_named_vpn, vpnName)); } else { - return mContext.getString(R.string.monitoring_description_app_personal, - primaryVpn); + message.append(mContext.getString(R.string.monitoring_description_named_vpn, + vpnName)); } - } else if (profileVpn != null) { - return mContext.getString(R.string.monitoring_description_app_work, - profileOwnerPackage, profileVpn); - } else if (profileOwnerPackage != null && hasProfileOwner) { - return mContext.getString(R.string.do_disclosure_with_name, - profileOwnerPackage); - } else { - // No device owner, no personal VPN, no work VPN, no user owner. Why are we here? - return null; } + message.append(mContext.getString(R.string.monitoring_description_vpn_settings_separator)); + message.append(mContext.getString(R.string.monitoring_description_vpn_settings), + new VpnSpan(), 0); + return message; } private int getTitle(String deviceOwner) { @@ -397,26 +433,23 @@ public class QSSecurityFooter implements OnClickListener, DialogInterface.OnClic } } - protected class EnterprisePrivacySpan extends ClickableSpan { + protected class VpnSpan extends ClickableSpan { @Override public void onClick(View widget) { - final Intent intent = new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS); + final Intent intent = new Intent(Settings.ACTION_VPN_SETTINGS); mDialog.dismiss(); mActivityStarter.postStartActivityDismissingKeyguard(intent, 0); } + // for testing, to compare two CharSequences containing VpnSpans @Override public boolean equals(Object object) { - return object instanceof EnterprisePrivacySpan; + return object instanceof VpnSpan; } - } - protected class VpnSpan extends ClickableSpan { @Override - public void onClick(View widget) { - final Intent intent = new Intent(Settings.ACTION_VPN_SETTINGS); - mDialog.dismiss(); - mActivityStarter.postStartActivityDismissingKeyguard(intent, 0); + public int hashCode() { + return 314159257; // prime } } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java index ff644d8bb618..ebd266b87d6c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java @@ -312,62 +312,72 @@ public class QSSecurityFooterTest extends SysuiTestCase { } @Test - public void testGetMessageWithNoOrganizationAndNoVPN() { - assertEquals(getExpectedMessage(false /* hasDeviceOwnerOrganization */, false /* hasVPN */), - mFooter.getMessage(DEVICE_OWNER_PACKAGE, - null /* profileOwnerPackage */, - null /* primaryVpn */, - null /* profileVpn */, - null /* deviceOwnerOrganization */, - false /* hasProfileOwner */)); + public void testGetManagementMessage() { + assertEquals(null, mFooter.getManagementMessage(false, MANAGING_ORGANIZATION)); + assertEquals(mContext.getString(R.string.monitoring_description_named_management, + MANAGING_ORGANIZATION), + mFooter.getManagementMessage(true, MANAGING_ORGANIZATION)); + assertEquals(mContext.getString(R.string.monitoring_description_management), + mFooter.getManagementMessage(true, null)); } @Test - public void testGetMessageWithNoOrganizationAndVPN() { - assertEquals(getExpectedMessage(false /* hasDeviceOwnerOrganization */, true /* hasVPN */), - mFooter.getMessage(DEVICE_OWNER_PACKAGE, - null /* profileOwnerPackage */, - VPN_PACKAGE, - null /* profileVpn */, - null /* deviceOwnerOrganization */, - false /* hasProfileOwner */)); + public void testGetCaCertsMessage() { + assertEquals(null, mFooter.getCaCertsMessage(true, false, false)); + assertEquals(null, mFooter.getCaCertsMessage(false, false, false)); + assertEquals(mContext.getString(R.string.monitoring_description_management_ca_certificate), + mFooter.getCaCertsMessage(true, true, true)); + assertEquals(mContext.getString(R.string.monitoring_description_management_ca_certificate), + mFooter.getCaCertsMessage(true, false, true)); + assertEquals(mContext.getString( + R.string.monitoring_description_managed_profile_ca_certificate), + mFooter.getCaCertsMessage(false, false, true)); + assertEquals(mContext.getString( + R.string.monitoring_description_ca_certificate), + mFooter.getCaCertsMessage(false, true, false)); } @Test - public void testGetMessageWithOrganizationAndNoVPN() { - assertEquals(getExpectedMessage(true /* hasDeviceOwnerOrganization */, false /* hasVPN */), - mFooter.getMessage(DEVICE_OWNER_PACKAGE, - null /* profileOwnerPackage */, - null /* primaryVpn */, - null /* profileVpn */, - MANAGING_ORGANIZATION, - false /* hasProfileOwner */)); + public void testGetNetworkLoggingMessage() { + assertEquals(null, mFooter.getNetworkLoggingMessage(false)); + assertEquals(mContext.getString(R.string.monitoring_description_management_network_logging), + mFooter.getNetworkLoggingMessage(true)); } @Test - public void testGetMessageWithOrganizationAndVPN() { - assertEquals(getExpectedMessage(true /* hasDeviceOwnerOrganization */, true /* hasVPN */), - mFooter.getMessage(DEVICE_OWNER_PACKAGE, - null /* profileOwnerPackage */, - VPN_PACKAGE, - null /* profileVpn */, - MANAGING_ORGANIZATION, - false /* hasProfileOwner */)); + public void testGetVpnMessage() { + assertEquals(null, mFooter.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)); + 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)); + assertEquals(addLink(mContext.getString(R.string.monitoring_description_named_vpn, + VPN_PACKAGE)), + mFooter.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)); + assertEquals(addLink(mContext.getString(R.string.monitoring_description_named_vpn, + VPN_PACKAGE_2)), + mFooter.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)); + assertEquals(addLink(mContext.getString( + R.string.monitoring_description_personal_profile_named_vpn, + VPN_PACKAGE)), + mFooter.getVpnMessage(false, true, VPN_PACKAGE, null)); } - private CharSequence getExpectedMessage(boolean hasDeviceOwnerOrganization, boolean hasVPN) { + private CharSequence addLink(CharSequence description) { final SpannableStringBuilder message = new SpannableStringBuilder(); - message.append(hasDeviceOwnerOrganization ? - mContext.getString(R.string.monitoring_description_do_header_with_name, - MANAGING_ORGANIZATION, DEVICE_OWNER_PACKAGE) : - mContext.getString(R.string.monitoring_description_do_header_generic, - DEVICE_OWNER_PACKAGE)); - message.append("\n\n"); - message.append(mContext.getString(R.string.monitoring_description_do_body)); - message.append(mContext.getString( - R.string.monitoring_description_do_learn_more_separator)); - message.append(mContext.getString(R.string.monitoring_description_do_learn_more), - mFooter.new EnterprisePrivacySpan(), 0); + 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); return message; } } |