Clean up cert activity handling

Fix re-displaying the dialog on orientation change b/5622284
Add host/port when available b/4988512
Disambiguate intent between AOSP and EmailGoogle

Change-Id: Ideeda20dfd9bd0070998ccf42d8042765866ca0e
This commit is contained in:
Tony Mantler 2014-06-05 13:05:42 -07:00
parent 9909fabcc6
commit f765f9b976
4 changed files with 25 additions and 14 deletions

View File

@ -19,6 +19,7 @@ package com.android.emailcommon.utility;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.security.KeyChain;
import android.security.KeyChainAliasCallback;
@ -28,14 +29,14 @@ import android.security.KeyChainAliasCallback;
* a certificate to use for establishing secure connections in the Email app.
*/
public class CertificateRequestor extends Activity implements KeyChainAliasCallback {
public static final String ACTION_REQUEST_CERT = "com.android.emailcommon.REQUEST_CERT";
public static final String EXTRA_HOST = "CertificateRequestor.host";
public static final String EXTRA_PORT = "CertificateRequestor.port";
public static final String RESULT_ALIAS = "CertificateRequestor.alias";
public static final Uri CERTIFICATE_REQUEST_URI =
Uri.parse("eas://com.android.emailcommon/certrequest");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -44,11 +45,13 @@ public class CertificateRequestor extends Activity implements KeyChainAliasCallb
String host = i.getStringExtra(EXTRA_HOST);
int port = i.getIntExtra(EXTRA_PORT, -1);
KeyChain.choosePrivateKeyAlias(
this, this,
null /* keytypes */, null /* issuers */,
host, port,
null /* alias */);
if (savedInstanceState == null) {
KeyChain.choosePrivateKeyAlias(
this, this,
null /* keytypes */, null /* issuers */,
host, port,
null /* alias */);
}
}
/**

View File

@ -839,6 +839,7 @@
<string name="account_manager_type_imap" translatable="false">com.android.email</string>
<string name="account_manager_type_legacy_imap" translatable="false">com.android.email</string>
<string name="intent_exchange_action" translatable="false">com.android.email.EXCHANGE_INTENT</string>
<string name="intent_exchange_cert_action" translatable="false">com.android.email.EXCHANGE_REQUEST_CERT</string>
<string name="intent_exchange_package" translatable="false">com.android.exchange</string>
<string name="intent_account_manager_entry" translatable="false">com.android.email.activity.setup.ACCOUNT_MANAGER_ENTRY</string>
<string name="intent_create_account" translatable="false">com.android.email.CREATE_ACCOUNT</string>

View File

@ -18,7 +18,6 @@ package com.android.email.activity.setup;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
@ -354,8 +353,10 @@ public class AccountSetupCredentialsFragment extends AccountSetupFragment
@Override
public void onCertificateRequested() {
final Intent intent = new Intent(CertificateRequestor.ACTION_REQUEST_CERT);
intent.setData(Uri.parse("eas://com.android.emailcommon/certrequest"));
final Intent intent = new Intent(getString(R.string.intent_exchange_cert_action));
intent.setData(CertificateRequestor.CERTIFICATE_REQUEST_URI);
// We don't set EXTRA_HOST or EXTRA_PORT here because we don't know the final host/port
// that we're connecting to yet, and autodiscover might point us somewhere else
startActivityForResult(intent, CERTIFICATE_REQUEST);
}
}

View File

@ -20,7 +20,6 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.Loader;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcel;
import android.text.Editable;
@ -611,8 +610,15 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
@Override
public void onCertificateRequested() {
final Intent intent = new Intent(CertificateRequestor.ACTION_REQUEST_CERT);
intent.setData(Uri.parse("eas://com.android.emailcommon/certrequest"));
final Intent intent = new Intent(getString(R.string.intent_exchange_cert_action));
intent.setData(CertificateRequestor.CERTIFICATE_REQUEST_URI);
intent.putExtra(CertificateRequestor.EXTRA_HOST, mServerView.getText().toString().trim());
try {
intent.putExtra(CertificateRequestor.EXTRA_PORT,
Integer.parseInt(mPortView.getText().toString().trim()));
} catch (final NumberFormatException e) {
LogUtils.d(LogUtils.TAG, "Couldn't parse port %s", mPortView.getText());
}
startActivityForResult(intent, CERTIFICATE_REQUEST);
}