am 6b1b36a8: Merge change 7687 into donut

Merge commit '6b1b36a832943126d19a21dcadda11cc75c3a9b6'

* commit '6b1b36a832943126d19a21dcadda11cc75c3a9b6':
  Add UI to handle PKCS12 cert.
This commit is contained in:
Android (Google) Code Review
2009-07-17 15:43:07 -07:00
committed by Android Git Automerger
3 changed files with 57 additions and 5 deletions

View File

@@ -46,6 +46,22 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:singleLine="True"/> android:singleLine="True"/>
<LinearLayout android:id="@+id/cstor_credential_password_container"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0dip">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/cstor_credential_password" />
<EditText android:id="@+id/cstor_credential_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:password="True"
android:singleLine="True"/>
</LinearLayout>
<TextView android:id="@+id/cstor_credential_info_title" <TextView android:id="@+id/cstor_credential_info_title"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@@ -1976,6 +1976,8 @@ found in the list of installed applications.</string>
<!-- Description for the credential name input box --> <!-- Description for the credential name input box -->
<string name="cstor_credential_name">Certificate name:</string> <string name="cstor_credential_name">Certificate name:</string>
<!-- Title of the credential info --> <!-- Title of the credential info -->
<!-- Description for the credential password input box -->
<string name="cstor_credential_password">Password to extract the certificate:</string>
<string name="cstor_credential_info">Certificate details:</string> <string name="cstor_credential_info">Certificate details:</string>
<string name="cstor_name_credential_hint">The name can contain only letters and numbers.</string> <string name="cstor_name_credential_hint">The name can contain only letters and numbers.</string>

View File

@@ -37,6 +37,7 @@ import android.preference.PreferenceCategory;
import android.preference.PreferenceGroup; import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.provider.Settings; import android.provider.Settings;
import android.security.CertTool;
import android.security.Keystore; import android.security.Keystore;
import android.text.Html; import android.text.Html;
import android.text.TextUtils; import android.text.TextUtils;
@@ -630,6 +631,17 @@ public class SecuritySettings extends PreferenceActivity implements
} }
mCstorAddCredentialHelper.setName(name); mCstorAddCredentialHelper.setName(name);
if (mCstorAddCredentialHelper.isPkcs12Keystore()) {
String password = getText(R.id.cstor_credential_password);
if (TextUtils.isEmpty(password)) {
showError(R.string.cstor_password_empty_error);
return false;
}
mCstorAddCredentialHelper.setPassword(password);
}
return true; return true;
} }
@@ -881,6 +893,9 @@ public class SecuritySettings extends PreferenceActivity implements
mView = View.inflate(SecuritySettings.this, mView = View.inflate(SecuritySettings.this,
R.layout.cstor_name_credential_dialog_view, null); R.layout.cstor_name_credential_dialog_view, null);
hideError(); hideError();
if (!mCstorAddCredentialHelper.isPkcs12Keystore()) {
hide(R.id.cstor_credential_password_container);
}
setText(R.id.cstor_credential_name_title, setText(R.id.cstor_credential_name_title,
R.string.cstor_credential_name); R.string.cstor_credential_name);
@@ -907,6 +922,7 @@ public class SecuritySettings extends PreferenceActivity implements
private List<String> mNamespaceList; private List<String> mNamespaceList;
private String mDescription; private String mDescription;
private String mName; private String mName;
private String mPassword;
CstorAddCredentialHelper(Intent intent) { CstorAddCredentialHelper(Intent intent) {
parse(intent); parse(intent);
@@ -916,6 +932,10 @@ public class SecuritySettings extends PreferenceActivity implements
return mTypeName; return mTypeName;
} }
boolean isPkcs12Keystore() {
return CertTool.TITLE_PKCS12_KEYSTORE.equals(mTypeName);
}
CharSequence getDescription() { CharSequence getDescription() {
return Html.fromHtml(mDescription); return Html.fromHtml(mDescription);
} }
@@ -928,13 +948,27 @@ public class SecuritySettings extends PreferenceActivity implements
return mName; return mName;
} }
void setPassword(String password) {
mPassword = password;
}
String getPassword() {
return mPassword;
}
int saveToStorage() { int saveToStorage() {
if (isPkcs12Keystore()) {
return CertTool.getInstance().addPkcs12Keystore(
mItemList.get(0), mPassword, mName);
} else {
Keystore ks = Keystore.getInstance(); Keystore ks = Keystore.getInstance();
for (int i = 0, count = mItemList.size(); i < count; i++) { for (int i = 0, count = mItemList.size(); i < count; i++) {
byte[] blob = mItemList.get(i); byte[] blob = mItemList.get(i);
int ret = ks.put(mNamespaceList.get(i), mName, new String(blob)); int ret = ks.put(mNamespaceList.get(i), mName,
new String(blob));
if (ret < 0) return ret; if (ret < 0) return ret;
} }
}
return 0; return 0;
} }