OSDN Git Service

Add button to trust a CA cert
authorVictor Chang <vichang@google.com>
Mon, 4 Apr 2016 18:10:28 +0000 (19:10 +0100)
committerVictor Chang <vichang@google.com>
Tue, 5 Apr 2016 21:22:41 +0000 (22:22 +0100)
- Put Disable button for system cert and Remove button for user cert as action button in cert dialog
- OK (dismiss) button is displayed when trust button is not shown
- Showing chain of cert dialot will be in a later CL

Bug: 18224038
Change-Id: Ieef70e12fd8bdf711be48dc0488f03dbe143d3c5

res/values/strings.xml
src/com/android/settings/TrustedCredentialsSettings.java

index 95a7749..84f2862 100644 (file)
     <string name="trusted_credentials_enable_label">Enable</string>
     <!-- Button label for removing a user CA certificate. -->
     <string name="trusted_credentials_remove_label">Remove</string>
+    <!-- Button label for trusting a user CA certificate. -->
+    <string name="trusted_credentials_trust_label">Trust</string>
     <!-- Alert dialog confirmation when enabling a system CA certificate. -->
     <string name="trusted_credentials_enable_confirmation">Enable the system CA certificate?</string>
     <!-- Alert dialog confirmation when disabling a system CA certificate. -->
index e1f0109..d8f7590 100644 (file)
@@ -19,6 +19,7 @@ package com.android.settings;
 import android.app.AlertDialog;
 import android.app.Dialog;
 import android.app.KeyguardManager;
+import android.app.admin.DevicePolicyManager;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.DialogInterface;
@@ -717,6 +718,7 @@ public class TrustedCredentialsSettings extends OptionsMenuFragment {
         AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
         builder.setTitle(com.android.internal.R.string.ssl_certificate);
 
+        final DevicePolicyManager dpm = getActivity().getSystemService(DevicePolicyManager.class);
         final ArrayList<View> views =  new ArrayList<View>();
         final ArrayList<String> titles = new ArrayList<String>();
         addCertChain(certHolder, views, titles);
@@ -728,16 +730,17 @@ public class TrustedCredentialsSettings extends OptionsMenuFragment {
         Spinner spinner = new Spinner(getActivity());
         spinner.setAdapter(arrayAdapter);
         spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
-                @Override
-                public void onItemSelected(AdapterView<?> parent, View view, int position,
-                        long id) {
-                    for(int i = 0; i < views.size(); i++) {
-                        views.get(i).setVisibility(i == position ? View.VISIBLE : View.GONE);
-                    }
+            @Override
+            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+                for (int i = 0; i < views.size(); i++) {
+                    views.get(i).setVisibility(i == position ? View.VISIBLE : View.GONE);
                 }
-               @Override
-               public void onNothingSelected(AdapterView<?> parent) { }
-            });
+            }
+
+            @Override
+            public void onNothingSelected(AdapterView<?> parent) {
+            }
+        });
 
         LinearLayout container = new LinearLayout(getActivity());
         container.setOrientation(LinearLayout.VERTICAL);
@@ -750,47 +753,47 @@ public class TrustedCredentialsSettings extends OptionsMenuFragment {
             container.addView(certificateView);
         }
         builder.setView(container);
-        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
-            @Override public void onClick(DialogInterface dialog, int id) {
-                dialog.dismiss();
-            }
-        });
-        final Dialog certDialog = builder.create();
 
-        ViewGroup body = (ViewGroup) container.findViewById(com.android.internal.R.id.body);
-        LayoutInflater inflater = LayoutInflater.from(getActivity());
-        Button removeButton = (Button) inflater.inflate(R.layout.trusted_credential_details,
-                                                        body,
-                                                        false);
+        if (certHolder.mTab == Tab.USER &&
+                !dpm.isCaCertApproved(certHolder.mAlias, certHolder.mProfileId)) {
+            builder.setPositiveButton(R.string.trusted_credentials_trust_label,
+                    new DialogInterface.OnClickListener() {
+                        @Override
+                        public void onClick(DialogInterface dialog, int id) {
+                            dpm.approveCaCert(certHolder.mAlias, certHolder.mProfileId, true);
+                        }
+                    });
+        } else {
+            // The ok button is optional. Display it only when trust button is not displayed.
+            // User can still dismiss the dialog by other means.
+            builder.setPositiveButton(android.R.string.ok, null);
+        }
+
         if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_CREDENTIALS,
                 new UserHandle(certHolder.mProfileId))) {
-            body.addView(removeButton);
-        }
-        removeButton.setText(certHolder.mTab.getButtonLabel(certHolder));
-        removeButton.setOnClickListener(new View.OnClickListener() {
-            @Override public void onClick(View v) {
-                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
-                builder.setMessage(certHolder.mTab.getButtonConfirmation(certHolder));
-                builder.setPositiveButton(
-                        android.R.string.yes, new DialogInterface.OnClickListener() {
-                    @Override public void onClick(DialogInterface dialog, int id) {
-                        new AliasOperation(certHolder).execute();
-                        dialog.dismiss();
-                        certDialog.dismiss();
-                    }
-                });
-                builder.setNegativeButton(
-                        android.R.string.no, new DialogInterface.OnClickListener() {
-                    @Override public void onClick(DialogInterface dialog, int id) {
-                        dialog.cancel();
-                    }
-                });
-                AlertDialog alert = builder.create();
-                alert.show();
-            }
-        });
+            builder.setNegativeButton(certHolder.mTab.getButtonLabel(certHolder),
+                    new DialogInterface.OnClickListener() {
+                        @Override
+                        public void onClick(final DialogInterface parentDialog, int i) {
+                            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+                            builder.setMessage(certHolder.mTab.getButtonConfirmation(certHolder));
+                            builder.setPositiveButton(android.R.string.yes,
+                                    new DialogInterface.OnClickListener() {
+                                        @Override
+                                        public void onClick(DialogInterface dialog, int id) {
+                                            new AliasOperation(certHolder).execute();
+                                            dialog.dismiss();
+                                            parentDialog.dismiss();
+                                        }
+                                    });
+                            builder.setNegativeButton(android.R.string.no, null);
+                            AlertDialog alert = builder.create();
+                            alert.show();
+                        }
+                    });
+        }
 
-        certDialog.show();
+        builder.show();
     }
 
     private void addCertChain(final CertHolder certHolder,