Add install-cert-from-sdcard in Security settings
Also:
* Resume keystore states in SecuritySettings.onResume().
* Use action strings defined in CertTool and Keystore.
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 06057e7..847e879 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2012,6 +2012,10 @@
<!-- Description of dialog to enable/dislable access to credential storage from an action that requires the credential storage -->
<string name="cstor_access_dialog_hint_from_action">Enter the credential storage password.</string>
+ <!-- Title of preference to install p12 cert from SD card -->
+ <string name="cstor_cert_install_title">Install from SD card</string>
+ <!-- Summary of preference to install p12 cert from SD card -->
+ <string name="cstor_cert_install_summary">Install encrypted certificates from SD card</string>
<!-- Title of preference to set storage password -->
<string name="cstor_set_passwd_title">Set password</string>
<!-- Summary of preference to set storage password -->
@@ -2052,7 +2056,7 @@
<string name="cstor_passwords_error">Passwords do not match.</string>
<string name="cstor_passwords_empty_error">You must enter and confirm a password.</string>
<string name="cstor_password_empty_error">Please enter the password.</string>
- <string name="cstor_password_verification_error">Please enter the password again. The password must have at least 8 characters and must not contain spaces.</string>
+ <string name="cstor_password_verification_error">Please enter the password again. The password must have at least 8 characters.</string>
<string name="cstor_name_empty_error">Please enter a name.</string>
<string name="cstor_name_char_error">Please enter a name that contains only letters and numbers.</string>
<string name="cstor_storage_error">Unable to save the certificate. Click OK to retry.</string>
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index 677432c..f3c53ce 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -87,10 +87,6 @@
private static final String ASSISTED_GPS = "assisted_gps";
// Credential storage
- public static final String ACTION_ADD_CREDENTIAL =
- "android.security.ADD_CREDENTIAL";
- public static final String ACTION_UNLOCK_CREDENTIAL_STORAGE =
- "android.security.UNLOCK_CREDENTIAL_STORAGE";
private static final String KEY_CSTOR_TYPE_NAME = "typeName";
private static final String KEY_CSTOR_ITEM = "item";
private static final String KEY_CSTOR_NAMESPACE = "namespace";
@@ -240,10 +236,10 @@
PreferenceCategory credStoreCat = new PreferenceCategory(this);
credStoreCat.setTitle(R.string.cstor_settings_category);
root.addPreference(credStoreCat);
- int s = mCstorHelper.getCstorState();
- credStoreCat.addPreference(mCstorHelper.createAccessCheckBox(s));
+ credStoreCat.addPreference(mCstorHelper.createAccessCheckBox());
+ credStoreCat.addPreference(mCstorHelper.createCertInstallPreference());
credStoreCat.addPreference(mCstorHelper.createSetPasswordPreference());
- credStoreCat.addPreference(mCstorHelper.createResetPreference(s));
+ credStoreCat.addPreference(mCstorHelper.createResetPreference());
return root;
}
@@ -269,6 +265,8 @@
mShowPassword
.setChecked(Settings.System.getInt(getContentResolver(),
Settings.System.TEXT_SHOW_PASSWORD, 1) != 0);
+
+ mCstorHelper.resumeStates();
}
@Override
@@ -504,10 +502,12 @@
if (intent == null) return;
String action = intent.getAction();
- if (ACTION_ADD_CREDENTIAL.equals(action)) {
- mCstorAddCredentialHelper = new CstorAddCredentialHelper(intent);
+ if (CertTool.ACTION_ADD_CREDENTIAL.equals(action)) {
+ mCstorAddCredentialHelper =
+ new CstorAddCredentialHelper(intent);
showCstorDialog(CSTOR_NAME_CREDENTIAL_DIALOG);
- } else if (ACTION_UNLOCK_CREDENTIAL_STORAGE.equals(action)) {
+ } else if (Keystore.ACTION_UNLOCK_CREDENTIAL_STORAGE.equals(
+ action)) {
mSpecialIntent = intent;
showCstorDialog(mCstorHelper.isCstorInitialized()
? CSTOR_UNLOCK_DIALOG
@@ -515,6 +515,13 @@
}
}
+ void resumeStates() {
+ int state = mCstorHelper.getCstorState();
+ mAccessCheckBox.setEnabled(state != Keystore.UNINITIALIZED);
+ mAccessCheckBox.setChecked(state == Keystore.UNLOCKED);
+ mResetButton.setEnabled(state != Keystore.UNINITIALIZED);
+ }
+
private void showCstorDialog(int dialogId) {
mDialogId = dialogId;
showDialog(dialogId);
@@ -732,8 +739,7 @@
if (passwd == null) {
showError(R.string.cstor_passwords_empty_error);
return false;
- } else if ((passwd.length() < CSTOR_MIN_PASSWORD_LENGTH)
- || passwd.contains(" ")) {
+ } else if (passwd.length() < CSTOR_MIN_PASSWORD_LENGTH) {
showError(R.string.cstor_password_verification_error);
return false;
} else {
@@ -803,6 +809,11 @@
}
}
+ private void installCertFromSdCard() {
+ // TODO: uncomment this when the feature is ready
+ //startActivity(new Intent(CertTool.ACTION_INSTALL_CERT_FROM_SDCARD));
+ }
+
private TextView showError(int messageId) {
TextView v = (TextView) mView.findViewById(R.id.cstor_error);
v.setText(messageId);
@@ -838,13 +849,11 @@
mResetButton.setEnabled(enabled);
}
- private Preference createAccessCheckBox(int state) {
+ private Preference createAccessCheckBox() {
CheckBoxPreference pref = new CheckBoxPreference(
SecuritySettings.this);
pref.setTitle(R.string.cstor_access_title);
pref.setSummary(R.string.cstor_access_summary);
- pref.setEnabled(state != Keystore.UNINITIALIZED);
- pref.setChecked(state == Keystore.UNLOCKED);
pref.setOnPreferenceChangeListener(
new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(
@@ -861,6 +870,20 @@
return pref;
}
+ private Preference createCertInstallPreference() {
+ Preference pref = new Preference(SecuritySettings.this);
+ pref.setTitle(R.string.cstor_cert_install_title);
+ pref.setSummary(R.string.cstor_cert_install_summary);
+ pref.setOnPreferenceClickListener(
+ new Preference.OnPreferenceClickListener() {
+ public boolean onPreferenceClick(Preference pref) {
+ installCertFromSdCard();
+ return true;
+ }
+ });
+ return pref;
+ }
+
private Preference createSetPasswordPreference() {
Preference pref = new Preference(SecuritySettings.this);
pref.setTitle(R.string.cstor_set_passwd_title);
@@ -877,7 +900,7 @@
return pref;
}
- private Preference createResetPreference(int state) {
+ private Preference createResetPreference() {
Preference pref = new Preference(SecuritySettings.this);
pref.setTitle(R.string.cstor_reset_title);
pref.setSummary(R.string.cstor_reset_summary);
@@ -888,7 +911,6 @@
return true;
}
});
- pref.setEnabled(state != Keystore.UNINITIALIZED);
mResetButton = pref;
return pref;
}
diff --git a/src/com/android/settings/vpn/VpnSettings.java b/src/com/android/settings/vpn/VpnSettings.java
index 61b2701..eea0aca 100644
--- a/src/com/android/settings/vpn/VpnSettings.java
+++ b/src/com/android/settings/vpn/VpnSettings.java
@@ -652,7 +652,7 @@
if (isKeystoreUnlocked()) return true;
mUnlockAction = action;
startActivity(
- new Intent(SecuritySettings.ACTION_UNLOCK_CREDENTIAL_STORAGE));
+ new Intent(Keystore.ACTION_UNLOCK_CREDENTIAL_STORAGE));
return false;
}
diff --git a/src/com/android/settings/wifi/AccessPointDialog.java b/src/com/android/settings/wifi/AccessPointDialog.java
index c4984cd..ce7ce92 100644
--- a/src/com/android/settings/wifi/AccessPointDialog.java
+++ b/src/com/android/settings/wifi/AccessPointDialog.java
@@ -17,7 +17,6 @@
package com.android.settings.wifi;
import com.android.settings.R;
-import com.android.settings.SecuritySettings;
import android.app.AlertDialog;
import android.content.Context;
@@ -802,7 +801,7 @@
// Unlock the keystore if it is not unlocked yet.
if (Keystore.getInstance().getState() != Keystore.UNLOCKED) {
getContext().startActivity(new Intent(
- SecuritySettings.ACTION_UNLOCK_CREDENTIAL_STORAGE));
+ Keystore.ACTION_UNLOCK_CREDENTIAL_STORAGE));
return;
}
enableEnterpriseFields();
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index adf4519..4aa5dc3 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -18,7 +18,6 @@
import com.android.settings.ProgressCategory;
import com.android.settings.R;
-import com.android.settings.SecuritySettings;
import android.app.Dialog;
import android.content.DialogInterface;
@@ -376,7 +375,7 @@
if (state.isEnterprise() &&
Keystore.getInstance().getState() != Keystore.UNLOCKED) {
startActivity(new Intent(
- SecuritySettings.ACTION_UNLOCK_CREDENTIAL_STORAGE));
+ Keystore.ACTION_UNLOCK_CREDENTIAL_STORAGE));
mResumeState = state;
mResumeMode = mode;
return;