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

Commit b49c901f authored by Victor Chang's avatar Victor Chang Committed by Android (Google) Code Review
Browse files

Merge "Add button to trust a CA cert" into nyc-dev

parents 4ffa5c8a a390d636
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -5229,6 +5229,8 @@
    <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. -->
+49 −46
Original line number Diff line number Diff line
@@ -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;
@@ -719,6 +720,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);
@@ -731,14 +733,15 @@ public class TrustedCredentialsSettings extends OptionsMenuFragment {
        spinner.setAdapter(arrayAdapter);
        spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position,
                        long id) {
            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) { }
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });

        LinearLayout container = new LinearLayout(getActivity());
@@ -752,47 +755,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();

        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);
                        }
                    });
        final Dialog certDialog = builder.create();
        } 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);
        }

        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 (!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) {
            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) {
                            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();
                                            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,