am 031ba6a3: Merge change 26365 into eclair

Merge commit '031ba6a3648367d307596f11b94367e50651397b' into eclair-plus-aosp

* commit '031ba6a3648367d307596f11b94367e50651397b':
  SecuritySettings: use Credentials instead of CertTool.
This commit is contained in:
Chia-chi Yeh
2009-09-22 09:08:01 -07:00
committed by Android Git Automerger
2 changed files with 146 additions and 444 deletions

View File

@@ -303,7 +303,8 @@
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<action android:name="android.settings.SECURITY_SETTINGS" /> <action android:name="android.settings.SECURITY_SETTINGS" />
<action android:name="android.settings.LOCATION_SOURCE_SETTINGS" /> <action android:name="android.settings.LOCATION_SOURCE_SETTINGS" />
<action android:name="android.security.UNLOCK_CREDENTIAL_STORAGE" /> <action android:name="android.credentials.UNLOCK" />
<action android:name="android.credentials.SYSTEM_INSTALL" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE_LAUNCH" /> <category android:name="android.intent.category.VOICE_LAUNCH" />
<category android:name="com.android.settings.SHORTCUT" /> <category android:name="com.android.settings.SHORTCUT" />

View File

@@ -38,8 +38,8 @@ 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.Credentials;
import android.security.Keystore; import android.security.KeyStore;
import android.text.Html; import android.text.Html;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
@@ -87,17 +87,12 @@ public class SecuritySettings extends PreferenceActivity implements
private static final String ASSISTED_GPS = "assisted_gps"; private static final String ASSISTED_GPS = "assisted_gps";
// Credential storage // 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";
private static final String KEY_CSTOR_DESCRIPTION = "description";
private static final int CSTOR_MIN_PASSWORD_LENGTH = 8; private static final int CSTOR_MIN_PASSWORD_LENGTH = 8;
private static final int CSTOR_INIT_DIALOG = 1; private static final int CSTOR_INIT_DIALOG = 1;
private static final int CSTOR_CHANGE_PASSWORD_DIALOG = 2; private static final int CSTOR_CHANGE_PASSWORD_DIALOG = 2;
private static final int CSTOR_UNLOCK_DIALOG = 3; private static final int CSTOR_UNLOCK_DIALOG = 3;
private static final int CSTOR_RESET_DIALOG = 4; private static final int CSTOR_RESET_DIALOG = 4;
private static final int CSTOR_NAME_CREDENTIAL_DIALOG = 5;
private CstorHelper mCstorHelper = new CstorHelper(); private CstorHelper mCstorHelper = new CstorHelper();
@@ -162,7 +157,7 @@ public class SecuritySettings extends PreferenceActivity implements
showUseLocationDialog(true); showUseLocationDialog(true);
} }
mCstorHelper.handleCstorIntents(getIntent()); mCstorHelper.handleIntent(getIntent());
} }
private PreferenceScreen createPreferenceHierarchy() { private PreferenceScreen createPreferenceHierarchy() {
@@ -236,10 +231,7 @@ public class SecuritySettings extends PreferenceActivity implements
PreferenceCategory credStoreCat = new PreferenceCategory(this); PreferenceCategory credStoreCat = new PreferenceCategory(this);
credStoreCat.setTitle(R.string.cstor_settings_category); credStoreCat.setTitle(R.string.cstor_settings_category);
root.addPreference(credStoreCat); root.addPreference(credStoreCat);
credStoreCat.addPreference(mCstorHelper.createAccessCheckBox()); mCstorHelper.createPreferences(credStoreCat);
credStoreCat.addPreference(mCstorHelper.createCertInstallPreference());
credStoreCat.addPreference(mCstorHelper.createSetPasswordPreference());
credStoreCat.addPreference(mCstorHelper.createResetPreference());
return root; return root;
} }
@@ -262,11 +254,8 @@ public class SecuritySettings extends PreferenceActivity implements
R.string.lockpattern_settings_choose_lock_pattern; R.string.lockpattern_settings_choose_lock_pattern;
mChoosePattern.setTitle(chooseStringRes); mChoosePattern.setTitle(chooseStringRes);
mShowPassword mShowPassword.setChecked(Settings.System.getInt(getContentResolver(),
.setChecked(Settings.System.getInt(getContentResolver(),
Settings.System.TEXT_SHOW_PASSWORD, 1) != 0); Settings.System.TEXT_SHOW_PASSWORD, 1) != 0);
mCstorHelper.resumeStates();
} }
@Override @Override
@@ -380,7 +369,6 @@ public class SecuritySettings extends PreferenceActivity implements
Settings.Secure.USE_LOCATION_FOR_SERVICES, use ? 1 : 0); Settings.Secure.USE_LOCATION_FOR_SERVICES, use ? 1 : 0);
} }
/** /**
* For the user to disable keyguard, we first make them verify their * For the user to disable keyguard, we first make them verify their
* existing pattern. * existing pattern.
@@ -459,9 +447,6 @@ public class SecuritySettings extends PreferenceActivity implements
case CSTOR_RESET_DIALOG: case CSTOR_RESET_DIALOG:
return mCstorHelper.createResetDialog(); return mCstorHelper.createResetDialog();
case CSTOR_NAME_CREDENTIAL_DIALOG:
return mCstorHelper.createNameCredentialDialog();
default: default:
return null; return null;
} }
@@ -485,213 +470,139 @@ public class SecuritySettings extends PreferenceActivity implements
} }
private class CstorHelper implements DialogInterface.OnClickListener, private class CstorHelper implements DialogInterface.OnClickListener,
DialogInterface.OnDismissListener, DialogInterface.OnDismissListener {
DialogInterface.OnCancelListener { private KeyStore mKeyStore = KeyStore.getInstance();
private Keystore mKeystore = Keystore.getInstance(); private int mState;
private View mView; private View mView;
private int mDialogId; private int mDialogId;
private boolean mConfirm = true; private boolean mRetry = false;
private CheckBoxPreference mAccessCheckBox; private CheckBoxPreference mAccessCheckBox;
private Preference mResetButton; private Preference mResetButton;
private Intent mSpecialIntent; private Intent mExternalIntent;
private CstorAddCredentialHelper mCstorAddCredentialHelper;
void handleCstorIntents(Intent intent) { CstorHelper() {
mState = mKeyStore.test();
}
void handleIntent(Intent intent) {
if (intent == null) return; if (intent == null) return;
String action = intent.getAction(); String action = intent.getAction();
if (CertTool.ACTION_ADD_CREDENTIAL.equals(action)) { if (Credentials.UNLOCK_ACTION.equals(action)) {
mCstorAddCredentialHelper = mExternalIntent = intent;
new CstorAddCredentialHelper(intent); showCstorDialog(mState == KeyStore.UNINITIALIZED
showCstorDialog(CSTOR_NAME_CREDENTIAL_DIALOG); ? CSTOR_INIT_DIALOG : CSTOR_UNLOCK_DIALOG);
} else if (Keystore.ACTION_UNLOCK_CREDENTIAL_STORAGE.equals( } else if (Credentials.SYSTEM_INSTALL_ACTION.equals(action)) {
action)) { mExternalIntent = intent;
mSpecialIntent = intent; // TODO: unlock and install.
showCstorDialog(mCstorHelper.isCstorInitialized()
? CSTOR_UNLOCK_DIALOG
: CSTOR_INIT_DIALOG);
} }
} }
void resumeStates() { private void updatePreferences(int state) {
int state = mCstorHelper.getCstorState(); mAccessCheckBox.setEnabled(state != KeyStore.UNINITIALIZED);
mAccessCheckBox.setEnabled(state != Keystore.UNINITIALIZED); mAccessCheckBox.setChecked(state == KeyStore.NO_ERROR);
mAccessCheckBox.setChecked(state == Keystore.UNLOCKED); mResetButton.setEnabled(state != KeyStore.UNINITIALIZED);
mResetButton.setEnabled(state != Keystore.UNINITIALIZED);
// Show a toast message if the state is changed.
if (mState == state) return;
if (state == KeyStore.NO_ERROR) {
Toast.makeText(SecuritySettings.this, R.string.cstor_is_enabled,
Toast.LENGTH_SHORT).show();
} else if (state == KeyStore.UNINITIALIZED) {
Toast.makeText(SecuritySettings.this, R.string.cstor_is_reset,
Toast.LENGTH_LONG).show();
}
// TODO: disabled?
mState = state;
}
private void lockCstor() {
mKeyStore.lock();
updatePreferences(KeyStore.LOCKED);
}
private int unlockCstor(String passwd) {
mKeyStore.unlock(passwd);
return mKeyStore.getLastError();
}
private int changeCstorPassword(String oldPasswd, String newPasswd) {
mKeyStore.password(oldPasswd, newPasswd);
return mKeyStore.getLastError();
}
private void initCstor(String passwd) {
mKeyStore.password(passwd);
updatePreferences(KeyStore.NO_ERROR);
}
private void resetCstor() {
mKeyStore.reset();
updatePreferences(KeyStore.UNINITIALIZED);
} }
private void showCstorDialog(int dialogId) { private void showCstorDialog(int dialogId) {
mDialogId = dialogId; mDialogId = dialogId;
showDialog(dialogId); showDialog(dialogId);
if (dialogId == CSTOR_NAME_CREDENTIAL_DIALOG) {
// set mView back as mView may be replaced by CSTOR_INIT_DIALOG
// or CSTOR_UNLOCK_DIALOG
mView = mCstorAddCredentialHelper.mView;
}
}
private int getCstorState() {
return mKeystore.getState();
}
private boolean isCstorUnlocked() {
return (mKeystore.getState() == Keystore.UNLOCKED);
}
private boolean isCstorInitialized() {
return (mKeystore.getState() != Keystore.UNINITIALIZED);
}
private void lockCstor() {
mKeystore.lock();
mAccessCheckBox.setChecked(false);
}
private int unlockCstor(String passwd) {
int ret = mKeystore.unlock(passwd);
if (ret == -1) resetCstor();
if (ret == 0) {
Toast.makeText(SecuritySettings.this, R.string.cstor_is_enabled,
Toast.LENGTH_SHORT).show();
}
return ret;
}
private int changeCstorPassword(String oldPasswd, String newPasswd) {
int ret = mKeystore.changePassword(oldPasswd, newPasswd);
if (ret == -1) resetCstor();
return ret;
}
private void initCstor(String passwd) {
mKeystore.setPassword(passwd);
enablePreferences(true);
mAccessCheckBox.setChecked(true);
Toast.makeText(SecuritySettings.this, R.string.cstor_is_enabled,
Toast.LENGTH_SHORT).show();
}
private void resetCstor() {
mKeystore.reset();
enablePreferences(false);
mAccessCheckBox.setChecked(false);
Toast.makeText(SecuritySettings.this, R.string.cstor_is_reset,
Toast.LENGTH_LONG).show();
}
private boolean addCredential() {
if (mCstorAddCredentialHelper.saveToStorage() != 0) {
// set mView back as mView may be replaced by CSTOR_INIT_DIALOG
// or CSTOR_UNLOCK_DIALOG
mView = mCstorAddCredentialHelper.mView;
if (mCstorAddCredentialHelper.isPkcs12Keystore()) {
showError(R.string.cstor_password_error);
} else {
showError(R.string.cstor_storage_error);
}
Log.d("CSTOR", "failed to add credential");
return false;
}
Log.d("CSTOR", "credential is added: "
+ mCstorAddCredentialHelper.getName());
String formatString =
getString(R.string.cstor_is_added);
String message = String.format(formatString,
mCstorAddCredentialHelper.getName());
Toast.makeText(SecuritySettings.this, message,
Toast.LENGTH_LONG).show();
return true;
}
public void onCancel(DialogInterface dialog) {
if (mCstorAddCredentialHelper == null) return;
switch (mDialogId) {
case CSTOR_INIT_DIALOG:
case CSTOR_UNLOCK_DIALOG:
Toast.makeText(SecuritySettings.this,
R.string.cstor_unable_to_save_cert,
Toast.LENGTH_LONG).show();
break;
case CSTOR_NAME_CREDENTIAL_DIALOG:
Toast.makeText(SecuritySettings.this,
R.string.cstor_cert_not_saved,
Toast.LENGTH_LONG).show();
break;
}
mCstorAddCredentialHelper = null;
finish();
} }
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_NEGATIVE) { if (which == DialogInterface.BUTTON_NEGATIVE) return;
onCancel(dialog);
return;
}
switch (mDialogId) { switch (mDialogId) {
case CSTOR_INIT_DIALOG: case CSTOR_INIT_DIALOG:
case CSTOR_CHANGE_PASSWORD_DIALOG: case CSTOR_CHANGE_PASSWORD_DIALOG:
mConfirm = checkPasswords((Dialog) dialog); mRetry = !checkPasswords((Dialog) dialog);
break; break;
case CSTOR_UNLOCK_DIALOG: case CSTOR_UNLOCK_DIALOG:
mConfirm = checkUnlockPassword((Dialog) dialog); mRetry = !checkPassword((Dialog) dialog);
break; break;
case CSTOR_RESET_DIALOG: case CSTOR_RESET_DIALOG:
resetCstor(); resetCstor();
break; break;
case CSTOR_NAME_CREDENTIAL_DIALOG:
mConfirm = checkAddCredential();
break;
} }
} }
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
if (!mConfirm) { if (mRetry) {
mConfirm = true;
showCstorDialog(mDialogId); showCstorDialog(mDialogId);
} else { } else {
if (mDialogId == CSTOR_UNLOCK_DIALOG) { removeDialog(mDialogId);
mAccessCheckBox.setChecked(isCstorUnlocked());
}
if (mCstorAddCredentialHelper != null) { if (mExternalIntent != null) {
if (!isCstorInitialized()) { if (Credentials.SYSTEM_INSTALL_ACTION.equals(
showCstorDialog(CSTOR_INIT_DIALOG); mExternalIntent.getAction())) {
} else if (!isCstorUnlocked()) { // TODO: install if unlocked.
showCstorDialog(CSTOR_UNLOCK_DIALOG);
} else { } else {
if (addCredential()) {
// succeeded
finish();
} else {
// failed
if (mDialogId != CSTOR_NAME_CREDENTIAL_DIALOG) {
removeDialog(mDialogId);
}
showCstorDialog(CSTOR_NAME_CREDENTIAL_DIALOG);
}
}
return;
} else if (mSpecialIntent != null) {
finish(); finish();
} }
removeDialog(mDialogId); }
} }
} }
private void showResetWarning(int count) { // returns false if there is no error.
TextView v = showError(count <= 3 private boolean checkError(int error) {
? R.string.cstor_password_error_reset_warning if (error == KeyStore.NO_ERROR) {
: R.string.cstor_password_error); updatePreferences(KeyStore.NO_ERROR);
if (count <= 3) { return false;
}
if (error == KeyStore.UNINITIALIZED) {
updatePreferences(KeyStore.UNINITIALIZED);
return false;
}
if (error < KeyStore.WRONG_PASSWORD) {
return false;
}
int count = error - KeyStore.WRONG_PASSWORD + 1;
if (count > 3) {
showError(R.string.cstor_password_error);
return true;
}
TextView v = showError(R.string.cstor_password_error_reset_warning);
if (count == 1) { if (count == 1) {
v.setText(R.string.cstor_password_error_reset_warning); v.setText(R.string.cstor_password_error_reset_warning);
} else { } else {
@@ -699,56 +610,11 @@ public class SecuritySettings extends PreferenceActivity implements
R.string.cstor_password_error_reset_warning_plural); R.string.cstor_password_error_reset_warning_plural);
v.setText(String.format(format, count)); v.setText(String.format(format, count));
} }
}
}
private boolean checkAddCredential() {
hideError();
String name = getText(R.id.cstor_credential_name);
if (TextUtils.isEmpty(name)) {
showError(R.string.cstor_name_empty_error);
return false;
}
for (int i = 0, len = name.length(); i < len; i++) {
if (!Character.isLetterOrDigit(name.charAt(i))) {
showError(R.string.cstor_name_char_error);
return false;
}
}
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;
} }
// returns true if the password is long enough and does not contain // returns true if the password is correct
// characters that we don't like private boolean checkPassword(Dialog d) {
private boolean verifyPassword(String passwd) {
if (passwd == null) {
showError(R.string.cstor_passwords_empty_error);
return false;
} else if (passwd.length() < CSTOR_MIN_PASSWORD_LENGTH) {
showError(R.string.cstor_password_verification_error);
return false;
} else {
return true;
}
}
// returns true if the password is ok
private boolean checkUnlockPassword(Dialog d) {
hideError(); hideError();
String passwd = getText(R.id.cstor_password); String passwd = getText(R.id.cstor_password);
@@ -757,17 +623,10 @@ public class SecuritySettings extends PreferenceActivity implements
return false; return false;
} }
int count = unlockCstor(passwd); return !checkError(unlockCstor(passwd));
if (count > 0) {
showResetWarning(count);
return false;
} else {
// done or reset
return true;
}
} }
// returns true if the passwords are ok // returns true if the passwords are correct
private boolean checkPasswords(Dialog d) { private boolean checkPasswords(Dialog d) {
hideError(); hideError();
@@ -778,39 +637,22 @@ public class SecuritySettings extends PreferenceActivity implements
if ((mDialogId == CSTOR_CHANGE_PASSWORD_DIALOG) if ((mDialogId == CSTOR_CHANGE_PASSWORD_DIALOG)
&& TextUtils.isEmpty(oldPasswd)) { && TextUtils.isEmpty(oldPasswd)) {
showError(R.string.cstor_password_empty_error); showError(R.string.cstor_password_empty_error);
return false; } else if (TextUtils.isEmpty(newPasswd)
} || TextUtils.isEmpty(confirmPasswd)) {
if (TextUtils.isEmpty(newPasswd)
&& TextUtils.isEmpty(confirmPasswd)) {
showError(R.string.cstor_passwords_empty_error); showError(R.string.cstor_passwords_empty_error);
return false; } else if (newPasswd.length() < CSTOR_MIN_PASSWORD_LENGTH) {
} showError(R.string.cstor_password_verification_error);
if (!verifyPassword(newPasswd)) {
return false;
} else if (!newPasswd.equals(confirmPasswd)) { } else if (!newPasswd.equals(confirmPasswd)) {
showError(R.string.cstor_passwords_error); showError(R.string.cstor_passwords_error);
return false;
}
if (mDialogId == CSTOR_CHANGE_PASSWORD_DIALOG) {
int count = changeCstorPassword(oldPasswd, newPasswd);
if (count > 0) {
showResetWarning(count);
return false;
} else { } else {
// done or reset if (mDialogId == CSTOR_CHANGE_PASSWORD_DIALOG) {
return true; return !checkError(changeCstorPassword(oldPasswd, newPasswd));
}
} else { } else {
initCstor(newPasswd); initCstor(newPasswd);
return true; return true;
} }
} }
return false;
private void installCertFromSdCard() {
startActivity(new Intent(CertTool.ACTION_INSTALL_CERT_FROM_SDCARD));
} }
private TextView showError(int messageId) { private TextView showError(int messageId) {
@@ -820,40 +662,24 @@ public class SecuritySettings extends PreferenceActivity implements
return v; return v;
} }
private void hideError() {
hide(R.id.cstor_error);
}
private void hide(int viewId) { private void hide(int viewId) {
View v = mView.findViewById(viewId); View v = mView.findViewById(viewId);
if (v != null) v.setVisibility(View.GONE); if (v != null) v.setVisibility(View.GONE);
} }
private void hideError() {
hide(R.id.cstor_error);
}
private String getText(int viewId) { private String getText(int viewId) {
return ((TextView) mView.findViewById(viewId)).getText().toString(); return ((TextView) mView.findViewById(viewId)).getText().toString();
} }
private void setText(int viewId, String text) { private void createPreferences(PreferenceCategory category) {
TextView v = (TextView) mView.findViewById(viewId); mAccessCheckBox = new CheckBoxPreference(SecuritySettings.this);
if (v != null) v.setText(text); mAccessCheckBox.setTitle(R.string.cstor_access_title);
} mAccessCheckBox.setSummary(R.string.cstor_access_summary);
mAccessCheckBox.setOnPreferenceChangeListener(
private void setText(int viewId, int textId) {
TextView v = (TextView) mView.findViewById(viewId);
if (v != null) v.setText(textId);
}
private void enablePreferences(boolean enabled) {
mAccessCheckBox.setEnabled(enabled);
mResetButton.setEnabled(enabled);
}
private Preference createAccessCheckBox() {
CheckBoxPreference pref = new CheckBoxPreference(
SecuritySettings.this);
pref.setTitle(R.string.cstor_access_title);
pref.setSummary(R.string.cstor_access_summary);
pref.setOnPreferenceChangeListener(
new Preference.OnPreferenceChangeListener() { new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange( public boolean onPreferenceChange(
Preference pref, Object value) { Preference pref, Object value) {
@@ -865,53 +691,48 @@ public class SecuritySettings extends PreferenceActivity implements
return true; return true;
} }
}); });
mAccessCheckBox = pref; category.addPreference(mAccessCheckBox);
return pref;
}
private Preference createCertInstallPreference() { Preference install = new Preference(SecuritySettings.this);
Preference pref = new Preference(SecuritySettings.this); install.setTitle(R.string.cstor_cert_install_title);
pref.setTitle(R.string.cstor_cert_install_title); install.setSummary(R.string.cstor_cert_install_summary);
pref.setSummary(R.string.cstor_cert_install_summary); install.setOnPreferenceClickListener(
pref.setOnPreferenceClickListener(
new Preference.OnPreferenceClickListener() { new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference pref) { public boolean onPreferenceClick(Preference pref) {
installCertFromSdCard(); Credentials.getInstance().installFromSdCard(
SecuritySettings.this);
return true; return true;
} }
}); });
return pref; category.addPreference(install);
}
private Preference createSetPasswordPreference() { Preference password = new Preference(SecuritySettings.this);
Preference pref = new Preference(SecuritySettings.this); password.setTitle(R.string.cstor_set_passwd_title);
pref.setTitle(R.string.cstor_set_passwd_title); password.setSummary(R.string.cstor_set_passwd_summary);
pref.setSummary(R.string.cstor_set_passwd_summary); password.setOnPreferenceClickListener(
pref.setOnPreferenceClickListener(
new Preference.OnPreferenceClickListener() { new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference pref) { public boolean onPreferenceClick(Preference pref) {
showCstorDialog(isCstorInitialized() showCstorDialog(mState == KeyStore.UNINITIALIZED
? CSTOR_CHANGE_PASSWORD_DIALOG ? CSTOR_INIT_DIALOG
: CSTOR_INIT_DIALOG); : CSTOR_CHANGE_PASSWORD_DIALOG);
return true; return true;
} }
}); });
return pref; category.addPreference(password);
}
private Preference createResetPreference() { mResetButton = new Preference(SecuritySettings.this);
Preference pref = new Preference(SecuritySettings.this); mResetButton.setTitle(R.string.cstor_reset_title);
pref.setTitle(R.string.cstor_reset_title); mResetButton.setSummary(R.string.cstor_reset_summary);
pref.setSummary(R.string.cstor_reset_summary); mResetButton.setOnPreferenceClickListener(
pref.setOnPreferenceClickListener(
new Preference.OnPreferenceClickListener() { new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference pref) { public boolean onPreferenceClick(Preference pref) {
showCstorDialog(CSTOR_RESET_DIALOG); showCstorDialog(CSTOR_RESET_DIALOG);
return true; return true;
} }
}); });
mResetButton = pref; category.addPreference(mResetButton);
return pref;
updatePreferences(mState);
} }
private Dialog createUnlockDialog() { private Dialog createUnlockDialog() {
@@ -920,8 +741,7 @@ public class SecuritySettings extends PreferenceActivity implements
hideError(); hideError();
// show extra hint only when the action comes from outside // show extra hint only when the action comes from outside
if ((mSpecialIntent == null) if (mExternalIntent == null) {
&& (mCstorAddCredentialHelper == null)) {
hide(R.id.cstor_access_dialog_hint_from_action); hide(R.id.cstor_access_dialog_hint_from_action);
} }
@@ -930,7 +750,6 @@ public class SecuritySettings extends PreferenceActivity implements
.setTitle(R.string.cstor_access_dialog_title) .setTitle(R.string.cstor_access_dialog_title)
.setPositiveButton(android.R.string.ok, this) .setPositiveButton(android.R.string.ok, this)
.setNegativeButton(android.R.string.cancel, this) .setNegativeButton(android.R.string.cancel, this)
.setOnCancelListener(this)
.create(); .create();
d.setOnDismissListener(this); d.setOnDismissListener(this);
return d; return d;
@@ -941,13 +760,6 @@ public class SecuritySettings extends PreferenceActivity implements
R.layout.cstor_set_password_dialog_view, null); R.layout.cstor_set_password_dialog_view, null);
hideError(); hideError();
// show extra hint only when the action comes from outside
if ((mSpecialIntent != null)
|| (mCstorAddCredentialHelper != null)) {
setText(R.id.cstor_first_time_hint,
R.string.cstor_first_time_hint_from_action);
}
switch (id) { switch (id) {
case CSTOR_INIT_DIALOG: case CSTOR_INIT_DIALOG:
mView.findViewById(R.id.cstor_old_password_block) mView.findViewById(R.id.cstor_old_password_block)
@@ -969,7 +781,6 @@ public class SecuritySettings extends PreferenceActivity implements
.setTitle(R.string.cstor_set_passwd_dialog_title) .setTitle(R.string.cstor_set_passwd_dialog_title)
.setPositiveButton(android.R.string.ok, this) .setPositiveButton(android.R.string.ok, this)
.setNegativeButton(android.R.string.cancel, this) .setNegativeButton(android.R.string.cancel, this)
.setOnCancelListener(this)
.create(); .create();
d.setOnDismissListener(this); d.setOnDismissListener(this);
return d; return d;
@@ -984,115 +795,5 @@ public class SecuritySettings extends PreferenceActivity implements
.setNegativeButton(getString(android.R.string.cancel), this) .setNegativeButton(getString(android.R.string.cancel), this)
.create(); .create();
} }
private Dialog createNameCredentialDialog() {
mView = View.inflate(SecuritySettings.this,
R.layout.cstor_name_credential_dialog_view, null);
if (mCstorAddCredentialHelper != null) {
mCstorAddCredentialHelper.mView = mView;
}
hideError();
if (!mCstorAddCredentialHelper.isPkcs12Keystore()) {
hide(R.id.cstor_credential_password_container);
}
setText(R.id.cstor_credential_name_title,
R.string.cstor_credential_name);
setText(R.id.cstor_credential_info_title,
R.string.cstor_credential_info);
setText(R.id.cstor_credential_info,
mCstorAddCredentialHelper.getDescription().toString());
Dialog d = new AlertDialog.Builder(SecuritySettings.this)
.setView(mView)
.setTitle(R.string.cstor_name_credential_dialog_title)
.setPositiveButton(android.R.string.ok, this)
.setNegativeButton(android.R.string.cancel, this)
.setOnCancelListener(this)
.create();
d.setOnDismissListener(this);
return d;
}
}
private class CstorAddCredentialHelper {
private String mTypeName;
private List<byte[]> mItemList;
private List<String> mNamespaceList;
private String mDescription;
private String mName;
private String mPassword;
private View mView;
CstorAddCredentialHelper(Intent intent) {
parse(intent);
}
String getTypeName() {
return mTypeName;
}
boolean isPkcs12Keystore() {
return CertTool.TITLE_PKCS12_KEYSTORE.equals(mTypeName);
}
CharSequence getDescription() {
return Html.fromHtml(mDescription);
}
void setName(String name) {
mName = name;
}
String getName() {
return mName;
}
void setPassword(String password) {
mPassword = password;
}
String getPassword() {
return mPassword;
}
int saveToStorage() {
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;
}
private void parse(Intent intent) {
mTypeName = intent.getStringExtra(KEY_CSTOR_TYPE_NAME);
mItemList = new ArrayList<byte[]>();
mNamespaceList = new ArrayList<String>();
for (int i = 0; ; i++) {
byte[] blob = intent.getByteArrayExtra(KEY_CSTOR_ITEM + i);
if (blob == null) break;
mItemList.add(blob);
mNamespaceList.add(intent.getStringExtra(
KEY_CSTOR_NAMESPACE + i));
}
// build description string
StringBuilder sb = new StringBuilder();
for (int i = 0; ; i++) {
String s = intent.getStringExtra(KEY_CSTOR_DESCRIPTION + i);
if (s == null) break;
sb.append(s).append("<br>");
}
mDescription = sb.toString();
}
} }
} }