From 17ead044e16878546828d2aedbbd187cfa17cac8 Mon Sep 17 00:00:00 2001 From: Victor Chang Date: Thu, 7 Apr 2016 17:49:45 +0100 Subject: [PATCH] "CA cert installed" notification should take PO into account - PO shows same dialog as DO, as shown in UI mock - Keep consumer message the same - Add cancel button - string change - remove TYPE_SYSTEM_ALERT due to the bug that the dialog is shown in primary user and bypass work challenge (Step: unlock work user -> launch dialog -> lock work user -> unlock personal user -> the dialog is still shown) - Remove dismissKeyguard, because I believe the dialog should still be protected by the keyguard Bug: 25772443 Bug: 18224038 Change-Id: I4f2580d1f6d2f88cfeadebcf6e8b0406e5c4b413 --- AndroidManifest.xml | 1 + res/values/strings.xml | 15 +++- .../settings/MonitoringCertInfoActivity.java | 82 ++++++++----------- 3 files changed, 46 insertions(+), 52 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index a1cb7ee3b7c..9e23115e68f 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1295,6 +1295,7 @@ diff --git a/res/values/strings.xml b/res/values/strings.xml index 84f2862ff1b..3977257d01a 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -5282,13 +5282,22 @@ Done - Network monitoring + + Trust or remove certificate + Trust or remove certificates + - This device is managed by:\n%s\n\nYour administrator is capable of monitoring your network activity, including emails, apps, and secure websites.\n\nFor more information, contact your administrator. + + %s has installed a certificate authority for your work profile, which may allow them to monitor work network activity, including emails, apps, and secure websites. You can choose to either trust or remove this certificate.\n\nFor more information about this certificate, contact your admin. + %s has installed certificate authorities for your work profile, which may allow them to monitor work network activity, including emails, apps, and secure websites. You can choose to either trust or remove these certificates.\n\nFor more information about these certificates, contact your admin. + A third party is capable of monitoring your network activity, including emails, apps, and secure websites.\n\nA trusted credential installed on your device is making this possible. - Check trusted credentials + + Check certificate + Check certificates + diff --git a/src/com/android/settings/MonitoringCertInfoActivity.java b/src/com/android/settings/MonitoringCertInfoActivity.java index ce65c8d3e9b..cfa8e6fb15a 100644 --- a/src/com/android/settings/MonitoringCertInfoActivity.java +++ b/src/com/android/settings/MonitoringCertInfoActivity.java @@ -18,81 +18,65 @@ package com.android.settings; import android.app.Activity; import android.app.AlertDialog; -import android.app.Dialog; import android.app.admin.DevicePolicyManager; -import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; +import android.content.DialogInterface.OnDismissListener; import android.content.Intent; import android.os.Bundle; -import android.os.RemoteException; import android.os.UserHandle; -import android.view.WindowManager; -import android.view.WindowManagerGlobal; +import android.provider.Settings; /** * Activity that shows a dialog explaining that a CA cert is allowing someone to monitor network - * traffic. + * traffic. This activity should be launched for the user into which the CA cert is installed. */ -public class MonitoringCertInfoActivity extends Activity implements OnClickListener { - - private boolean hasDeviceOwner = false; +public class MonitoringCertInfoActivity extends Activity implements OnClickListener, + OnDismissListener { @Override protected void onCreate(Bundle savedStates) { super.onCreate(savedStates); - DevicePolicyManager dpm = - (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); + DevicePolicyManager dpm = getSystemService(DevicePolicyManager.class); + final int numberOfCertificates = getIntent().getIntExtra( + Settings.EXTRA_NUMBER_OF_CERTIFICATES, 1); final AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.ssl_ca_cert_dialog_title); + builder.setTitle(getResources().getQuantityText(R.plurals.ssl_ca_cert_dialog_title, + numberOfCertificates)); builder.setCancelable(true); - // TODO See b/25772443 - hasDeviceOwner = dpm.getDeviceOwnerComponentOnCallingUser() != null; - int buttonLabel; - if (hasDeviceOwner) { - // Institutional case. Show informational message. - String message = this.getResources().getString(R.string.ssl_ca_cert_info_message, - dpm.getDeviceOwnerNameOnAnyUser()); - builder.setMessage(message); - buttonLabel = R.string.done_button; - } else { + builder.setPositiveButton(getResources().getQuantityText( + R.plurals.ssl_ca_cert_settings_button, numberOfCertificates) , this); + builder.setNeutralButton(R.string.cancel, null); + builder.setOnDismissListener(this); + + if (dpm.getProfileOwner() != null) { + builder.setMessage(getResources().getQuantityString(R.plurals.ssl_ca_cert_info_message, + numberOfCertificates, dpm.getProfileOwnerName())); + } else if (dpm.getDeviceOwnerComponentOnCallingUser() != null) { + builder.setMessage(getResources().getQuantityString(R.plurals.ssl_ca_cert_info_message, + numberOfCertificates, dpm.getDeviceOwnerNameOnAnyUser())); + } else { // Consumer case. Show scary warning. builder.setIcon(android.R.drawable.stat_notify_error); builder.setMessage(R.string.ssl_ca_cert_warning_message); - buttonLabel = R.string.ssl_ca_cert_settings_button; } - builder.setPositiveButton(buttonLabel, this); - - final Dialog dialog = builder.create(); - dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); - try { - WindowManagerGlobal.getWindowManagerService().dismissKeyguard(); - } catch (RemoteException e) { - } - dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { - @Override public void onCancel(DialogInterface dialog) { - finish(); - } - }); - - dialog.show(); + builder.show(); } @Override public void onClick(DialogInterface dialog, int which) { - if (hasDeviceOwner) { - finish(); - } else { - Intent intent = - new Intent(android.provider.Settings.ACTION_TRUSTED_CREDENTIALS_USER); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.putExtra(TrustedCredentialsSettings.ARG_SHOW_NEW_FOR_USER, - UserHandle.myUserId()); - startActivity(intent); - finish(); - } + Intent intent = new Intent(android.provider.Settings.ACTION_TRUSTED_CREDENTIALS_USER); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); + intent.putExtra(TrustedCredentialsSettings.ARG_SHOW_NEW_FOR_USER, UserHandle.myUserId()); + startActivity(intent); + finish(); + } + + @Override + public void onDismiss(DialogInterface dialogInterface) { + finish(); } }