diff --git a/emailcommon/src/com/android/emailcommon/utility/CertificateRequestor.java b/emailcommon/src/com/android/emailcommon/utility/CertificateRequestor.java new file mode 100644 index 000000000..b78895b3a --- /dev/null +++ b/emailcommon/src/com/android/emailcommon/utility/CertificateRequestor.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package com.android.emailcommon.utility; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.security.KeyChain; +import android.security.KeyChainAliasCallback; + +/** + * A headless Activity which simply calls into the framework {@link KeyChain} service to select + * 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"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + Intent i = getIntent(); + 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 */); + } + + /** + * Callback for the certificate request. Does not happen on the UI thread. + */ + @Override + public void alias(String alias) { + if (alias == null) { + setResult(RESULT_CANCELED); + } else { + Intent data = new Intent(); + data.putExtra(RESULT_ALIAS, alias); + setResult(RESULT_OK, data); + } + finish(); + } +} diff --git a/res/layout/client_certificate_selector.xml b/res/layout/client_certificate_selector.xml index 98e59269a..fcdd36af6 100644 --- a/res/layout/client_certificate_selector.xml +++ b/res/layout/client_certificate_selector.xml @@ -20,10 +20,8 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="8dip" - android:layout_marginBottom="8dip" - android:layout_marginLeft="32dip" - android:layout_marginRight="32dip" + android:layout_margin="8dip" + android:gravity="center_vertical" android:orientation="horizontal" >