Add UI to handle PKCS12 cert.
diff --git a/res/layout/cstor_name_credential_dialog_view.xml b/res/layout/cstor_name_credential_dialog_view.xml
index e5ccb36..33688bd 100644
--- a/res/layout/cstor_name_credential_dialog_view.xml
+++ b/res/layout/cstor_name_credential_dialog_view.xml
@@ -46,6 +46,22 @@
                 android:layout_height="wrap_content"
                 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"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f7d76a4..61f099c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1968,6 +1968,8 @@
     <!-- Description for the credential name input box -->
     <string name="cstor_credential_name">Certificate name:</string>
     <!-- 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_name_credential_hint">The name can contain only letters and numbers.</string>
 
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index 305fb7e..4947c2b 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -37,6 +37,7 @@
 import android.preference.PreferenceGroup;
 import android.preference.PreferenceScreen;
 import android.provider.Settings;
+import android.security.CertTool;
 import android.security.Keystore;
 import android.text.Html;
 import android.text.TextUtils;
@@ -618,6 +619,17 @@
             }
 
             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;
         }
 
@@ -869,6 +881,9 @@
             mView = View.inflate(SecuritySettings.this,
                     R.layout.cstor_name_credential_dialog_view, null);
             hideError();
+            if (!mCstorAddCredentialHelper.isPkcs12Keystore()) {
+                hide(R.id.cstor_credential_password_container);
+            }
 
             setText(R.id.cstor_credential_name_title,
                     R.string.cstor_credential_name);
@@ -895,6 +910,7 @@
         private List<String> mNamespaceList;
         private String mDescription;
         private String mName;
+        private String mPassword;
 
         CstorAddCredentialHelper(Intent intent) {
             parse(intent);
@@ -904,6 +920,10 @@
             return mTypeName;
         }
 
+        boolean isPkcs12Keystore() {
+            return CertTool.TITLE_PKCS12_KEYSTORE.equals(mTypeName);
+        }
+
         CharSequence getDescription() {
             return Html.fromHtml(mDescription);
         }
@@ -916,12 +936,26 @@
             return mName;
         }
 
+        void setPassword(String password) {
+            mPassword = password;
+        }
+
+        String getPassword() {
+            return mPassword;
+        }
+
         int saveToStorage() {
-            Keystore ks = Keystore.getInstance();
-            for (int i = 0, count = mItemList.size(); i < count; i++) {
-                byte[] blob = mItemList.get(i);
-                int ret = ks.put(mNamespaceList.get(i), mName, new String(blob));
-                if (ret < 0) return ret;
+            if (isPkcs12Keystore()) {
+                return CertTool.getInstance().addPkcs12Keystore(
+                        mItemList.get(0), mPassword, mName);
+            } else {
+                Keystore ks = Keystore.getInstance();
+                for (int i = 0, count = mItemList.size(); i < count; i++) {
+                    byte[] blob = mItemList.get(i);
+                    int ret = ks.put(mNamespaceList.get(i), mName,
+                            new String(blob));
+                    if (ret < 0) return ret;
+                }
             }
             return 0;
         }