Make certificate selector work

Change-Id: Id1ae8c9bb9467effc8feca9d915dc4927c4bbe25
This commit is contained in:
Martin Hibdon 2014-01-30 12:54:49 -08:00
parent 8a41d9fd10
commit d23fa61a01
3 changed files with 29 additions and 17 deletions

View File

@ -17,9 +17,9 @@
package com.android.email.activity.setup; package com.android.email.activity.setup;
import android.app.Activity; import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
@ -45,6 +45,7 @@ import com.android.email2.ui.MailActivityEmail;
import com.android.emailcommon.Logging; import com.android.emailcommon.Logging;
import com.android.emailcommon.provider.Account; import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.HostAuth; import com.android.emailcommon.provider.HostAuth;
import com.android.emailcommon.utility.CertificateRequestor;
import com.android.emailcommon.utility.Utility; import com.android.emailcommon.utility.Utility;
import com.android.mail.utils.LogUtils; import com.android.mail.utils.LogUtils;
@ -59,6 +60,8 @@ import java.util.ArrayList;
public class AccountSetupIncomingFragment extends AccountServerBaseFragment public class AccountSetupIncomingFragment extends AccountServerBaseFragment
implements AuthenticationCallback { implements AuthenticationCallback {
private static final int CERTIFICATE_REQUEST = 0;
private final static String STATE_KEY_CREDENTIAL = "AccountSetupIncomingFragment.credential"; private final static String STATE_KEY_CREDENTIAL = "AccountSetupIncomingFragment.credential";
private final static String STATE_KEY_LOADED = "AccountSetupIncomingFragment.loaded"; private final static String STATE_KEY_LOADED = "AccountSetupIncomingFragment.loaded";
@ -564,4 +567,20 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
public void onValidateStateChanged() { public void onValidateStateChanged() {
validateFields(); validateFields();
} }
@Override
public void onCertificateRequested() {
final Intent intent = new Intent(CertificateRequestor.ACTION_REQUEST_CERT);
intent.setData(Uri.parse("eas://com.android.emailcommon/certrequest"));
startActivityForResult(intent, CERTIFICATE_REQUEST);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CERTIFICATE_REQUEST && resultCode == Activity.RESULT_OK) {
final String certAlias = data.getStringExtra(CertificateRequestor.RESULT_ALIAS);
mAuthenticationView.setCertificate(certAlias);
}
}
} }

View File

@ -43,8 +43,6 @@ import java.io.IOException;
public class AuthenticationView extends LinearLayout implements HostCallback, OnClickListener { public class AuthenticationView extends LinearLayout implements HostCallback, OnClickListener {
private static final int CERTIFICATE_REQUEST = 0;
private final static String SUPER_STATE = "super_state"; private final static String SUPER_STATE = "super_state";
private final static String SAVE_PASSWORD = "save_password"; private final static String SAVE_PASSWORD = "save_password";
private final static String SAVE_OFFER_OAUTH = "save_offer_oauth"; private final static String SAVE_OFFER_OAUTH = "save_offer_oauth";
@ -83,6 +81,8 @@ public class AuthenticationView extends LinearLayout implements HostCallback, On
public interface AuthenticationCallback { public interface AuthenticationCallback {
public void onValidateStateChanged(); public void onValidateStateChanged();
public void onCertificateRequested();
} }
public AuthenticationView(Context context) { public AuthenticationView(Context context) {
@ -120,6 +120,8 @@ public class AuthenticationView extends LinearLayout implements HostCallback, On
mClearOAuthView.setOnClickListener(this); mClearOAuthView.setOnClickListener(this);
mAddAuthenticationView.setOnClickListener(this); mAddAuthenticationView.setOnClickListener(this);
mClientCertificateSelector.setHostCallback(this);
mValidationTextWatcher = new TextWatcher() { mValidationTextWatcher = new TextWatcher() {
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
@ -295,20 +297,11 @@ public class AuthenticationView extends LinearLayout implements HostCallback, On
@Override @Override
public void onCertificateRequested() { public void onCertificateRequested() {
final Intent intent = new Intent(CertificateRequestor.ACTION_REQUEST_CERT); mAuthenticationCallback.onCertificateRequested();
intent.setData(Uri.parse("eas://com.android.emailcommon/certrequest"));
// FLAG this is wrong, since this is not an activity or fragment, it cannot receive
// results directly. The owning activity or fragment needs to forward them.
// startActivityForResult(intent, CERTIFICATE_REQUEST);
} }
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void setCertificate(final String certAlias) {
if (requestCode == CERTIFICATE_REQUEST && resultCode == Activity.RESULT_OK) { mClientCertificateSelector.setCertificate(certAlias);
final String certAlias = data.getStringExtra(CertificateRequestor.RESULT_ALIAS);
if (certAlias != null) {
mClientCertificateSelector.setCertificate(certAlias);
}
}
} }
public void onUseSslChanged(boolean useSsl) { public void onUseSslChanged(boolean useSsl) {

View File

@ -63,7 +63,7 @@ public class CertificateSelector extends RelativeLayout implements OnClickListen
super(context, attrs, defStyle); super(context, attrs, defStyle);
} }
public void setHostActivity(HostCallback host) { public void setHostCallback(HostCallback host) {
mHost = host; mHost = host;
} }