From 9e450e12330d4cfe7843613c79f1c3671d08305f Mon Sep 17 00:00:00 2001 From: phweiss Date: Fri, 2 Dec 2016 14:31:04 +0100 Subject: [PATCH] Rework Device Monitoring Dialog in Quicksettings If a device owner is active, the layout is changed from a standard AlertDialog with only one string to a custom dialog that includes information on Device Owners, and VPN and Network Logging, if enabled. BUG: 29748723 BUG: 33126622 Test: Manual, CTS-Verifier tests will be added later Change-Id: I2bfca9d9d02a42d9c3b17683625eda29e9369666 --- .../res/drawable/ic_qs_network_logging.xml | 2 +- .../layout/quick_settings_footer_dialog.xml | 117 ++++++++++++++++++ packages/SystemUI/res/values/dimens.xml | 7 ++ packages/SystemUI/res/values/strings.xml | 23 +++- .../src/com/android/systemui/qs/QSFooter.java | 68 +++++++--- .../com/android/systemui/qs/QSFooterTest.java | 5 - 6 files changed, 194 insertions(+), 28 deletions(-) create mode 100644 packages/SystemUI/res/layout/quick_settings_footer_dialog.xml diff --git a/packages/SystemUI/res/drawable/ic_qs_network_logging.xml b/packages/SystemUI/res/drawable/ic_qs_network_logging.xml index 1340ae1617293..87b5a14153f72 100644 --- a/packages/SystemUI/res/drawable/ic_qs_network_logging.xml +++ b/packages/SystemUI/res/drawable/ic_qs_network_logging.xml @@ -24,6 +24,6 @@ Copyright (C) 2016 The Android Open Source Project android:tint="#4DFFFFFF" > + android:pathData="M2,24v-4h12v4H2z M2,16v-4h20v4H2z M5,7 12,0 19,7 14,7 14,15 10,15 10,7z"/> diff --git a/packages/SystemUI/res/layout/quick_settings_footer_dialog.xml b/packages/SystemUI/res/layout/quick_settings_footer_dialog.xml new file mode 100644 index 0000000000000..2ba04fd31c0fd --- /dev/null +++ b/packages/SystemUI/res/layout/quick_settings_footer_dialog.xml @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 5f9ade58fd4b6..ff4ec5bdaf3fc 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -258,6 +258,13 @@ 0dp + + 24sp + + 8sp + + 0.3 + 8dp diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 31b83cc8d8bb6..d5638a89b2fd3 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -1010,6 +1010,13 @@ Network monitoring + + + VPN + + + Network Logging + Disable VPN @@ -1025,15 +1032,25 @@ Your administrator can monitor and manage settings, corporate access, apps, data associated with your device, and your device\'s location information. - - You\'re connected to %1$s, which can monitor your network activity, including emails, apps, and websites. - " " Learn more + + You\'re connected to %1$s, which can monitor your network activity, including emails, apps, and websites. + + + " " + + + Open VPN Settings + + + Your admin has turned on network logging, which monitors traffic on your device.\n\nFor more information contact your admin. + + You gave an app permission to set up a VPN connection.\n\nThis app can monitor your device and network activity, including emails, apps, and websites. diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSFooter.java b/packages/SystemUI/src/com/android/systemui/qs/QSFooter.java index f3da47b1ba82d..0e4799b0f3e60 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSFooter.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSFooter.java @@ -31,6 +31,7 @@ import android.text.style.ClickableSpan; import android.util.Log; 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; @@ -175,6 +176,7 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene 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.getProfileVpnName(); final CharSequence deviceOwnerOrganization = @@ -186,24 +188,47 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene if (!isBranded) { mDialog.setTitle(getTitle(deviceOwnerPackage)); } - mDialog.setMessage(getMessage(deviceOwnerPackage, profileOwnerPackage, primaryVpn, - profileVpn, deviceOwnerOrganization, hasProfileOwner, isBranded)); + CharSequence msg = getMessage(deviceOwnerPackage, profileOwnerPackage, primaryVpn, + profileVpn, deviceOwnerOrganization, hasProfileOwner, isBranded); + if (deviceOwnerPackage == null) { + mDialog.setMessage(msg); + } 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)); + message.append(mContext.getString( + R.string.monitoring_description_vpn_settings_separator)); + message.append(mContext.getString(R.string.monitoring_description_vpn_settings), + new VpnSpan(), 0); - mDialog.setButton(DialogInterface.BUTTON_POSITIVE, getPositiveButton(isBranded), this); - if (mSecurityController.isVpnEnabled() && !mSecurityController.isVpnRestricted()) { - 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); + } } - // Make the link "learn more" clickable. - // TODO: Reaching into SystemUIDialog's internal View hierarchy is ugly and error-prone. - // This is a temporary solution. b/33126622 will introduce a custom View hierarchy for this - // dialog, allowing us to set the movement method on the appropriate View without any - // knowledge of SystemUIDialog's internals. - mDialog.create(); - ((TextView) mDialog.getWindow().findViewById(com.android.internal.R.id.message)) - .setMovementMethod(new LinkMovementMethod()); - + mDialog.setButton(DialogInterface.BUTTON_POSITIVE, getPositiveButton(isBranded), this); mDialog.show(); + mDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); } private String getSettingsButton() { @@ -229,11 +254,6 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene } message.append("\n\n"); message.append(mContext.getString(R.string.monitoring_description_do_body)); - if (primaryVpn != null) { - message.append("\n\n"); - message.append(mContext.getString(R.string.monitoring_description_do_body_vpn, - primaryVpn)); - } message.append(mContext.getString( R.string.monitoring_description_do_learn_more_separator)); message.append(mContext.getString(R.string.monitoring_description_do_learn_more), @@ -340,4 +360,14 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene return object instanceof EnterprisePrivacySpan; } } + + protected class VpnSpan extends ClickableSpan { + @Override + public void onClick(View widget) { + final Intent intent = new Intent(Settings.ACTION_VPN_SETTINGS); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); + mDialog.dismiss(); + mContext.startActivity(intent); + } + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSFooterTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/QSFooterTest.java index 4c25c62e82a3d..391c45fb84871 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSFooterTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSFooterTest.java @@ -217,11 +217,6 @@ public class QSFooterTest extends SysuiTestCase { DEVICE_OWNER_PACKAGE)); message.append("\n\n"); message.append(mResources.getString(R.string.monitoring_description_do_body)); - if (hasVPN) { - message.append("\n\n"); - message.append(mResources.getString(R.string.monitoring_description_do_body_vpn, - VPN_PACKAGE)); - } message.append(mResources.getString( R.string.monitoring_description_do_learn_more_separator)); message.append(mResources.getString(R.string.monitoring_description_do_learn_more),