diff options
author | Chia-chi Yeh <chiachi@android.com> | 2009-09-22 23:59:01 +0800 |
---|---|---|
committer | Chia-chi Yeh <chiachi@android.com> | 2009-09-22 23:59:01 +0800 |
commit | 9cec698a1fbbe5e8d23a96347d4e75003f4b8cb6 (patch) | |
tree | 329da54cb621a14bee6ae852827cb73f7b9991ef /src | |
parent | fc0139aa28d6d94ae868d6d794fa0c8ed621ecf8 (diff) | |
download | packages_apps_settings-9cec698a1fbbe5e8d23a96347d4e75003f4b8cb6.zip packages_apps_settings-9cec698a1fbbe5e8d23a96347d4e75003f4b8cb6.tar.gz packages_apps_settings-9cec698a1fbbe5e8d23a96347d4e75003f4b8cb6.tar.bz2 |
SecuritySettings: use Credentials instead of CertTool.
Also remove unused classes which will be replaced by CertInstaller.
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/settings/SecuritySettings.java | 553 |
1 files changed, 127 insertions, 426 deletions
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java index 24b89b1..3d7a765 100644 --- a/src/com/android/settings/SecuritySettings.java +++ b/src/com/android/settings/SecuritySettings.java @@ -38,8 +38,8 @@ import android.preference.PreferenceCategory; import android.preference.PreferenceGroup; import android.preference.PreferenceScreen; import android.provider.Settings; -import android.security.CertTool; -import android.security.Keystore; +import android.security.Credentials; +import android.security.KeyStore; import android.text.Html; import android.text.TextUtils; import android.text.method.LinkMovementMethod; @@ -87,17 +87,12 @@ public class SecuritySettings extends PreferenceActivity implements private static final String ASSISTED_GPS = "assisted_gps"; // 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_INIT_DIALOG = 1; private static final int CSTOR_CHANGE_PASSWORD_DIALOG = 2; private static final int CSTOR_UNLOCK_DIALOG = 3; private static final int CSTOR_RESET_DIALOG = 4; - private static final int CSTOR_NAME_CREDENTIAL_DIALOG = 5; private CstorHelper mCstorHelper = new CstorHelper(); @@ -162,7 +157,7 @@ public class SecuritySettings extends PreferenceActivity implements showUseLocationDialog(true); } - mCstorHelper.handleCstorIntents(getIntent()); + mCstorHelper.handleIntent(getIntent()); } private PreferenceScreen createPreferenceHierarchy() { @@ -236,10 +231,7 @@ public class SecuritySettings extends PreferenceActivity implements PreferenceCategory credStoreCat = new PreferenceCategory(this); credStoreCat.setTitle(R.string.cstor_settings_category); root.addPreference(credStoreCat); - credStoreCat.addPreference(mCstorHelper.createAccessCheckBox()); - credStoreCat.addPreference(mCstorHelper.createCertInstallPreference()); - credStoreCat.addPreference(mCstorHelper.createSetPasswordPreference()); - credStoreCat.addPreference(mCstorHelper.createResetPreference()); + mCstorHelper.createPreferences(credStoreCat); return root; } @@ -262,11 +254,8 @@ public class SecuritySettings extends PreferenceActivity implements R.string.lockpattern_settings_choose_lock_pattern; mChoosePattern.setTitle(chooseStringRes); - mShowPassword - .setChecked(Settings.System.getInt(getContentResolver(), + mShowPassword.setChecked(Settings.System.getInt(getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD, 1) != 0); - - mCstorHelper.resumeStates(); } @Override @@ -380,7 +369,6 @@ public class SecuritySettings extends PreferenceActivity implements Settings.Secure.USE_LOCATION_FOR_SERVICES, use ? 1 : 0); } - /** * For the user to disable keyguard, we first make them verify their * existing pattern. @@ -447,7 +435,7 @@ public class SecuritySettings extends PreferenceActivity implements } @Override - protected Dialog onCreateDialog (int id) { + protected Dialog onCreateDialog(int id) { switch (id) { case CSTOR_INIT_DIALOG: case CSTOR_CHANGE_PASSWORD_DIALOG: @@ -459,9 +447,6 @@ public class SecuritySettings extends PreferenceActivity implements case CSTOR_RESET_DIALOG: return mCstorHelper.createResetDialog(); - case CSTOR_NAME_CREDENTIAL_DIALOG: - return mCstorHelper.createNameCredentialDialog(); - default: return null; } @@ -485,270 +470,151 @@ public class SecuritySettings extends PreferenceActivity implements } private class CstorHelper implements DialogInterface.OnClickListener, - DialogInterface.OnDismissListener, - DialogInterface.OnCancelListener { - private Keystore mKeystore = Keystore.getInstance(); + DialogInterface.OnDismissListener { + private KeyStore mKeyStore = KeyStore.getInstance(); + private int mState; + private View mView; private int mDialogId; - private boolean mConfirm = true; - + private boolean mRetry = false; private CheckBoxPreference mAccessCheckBox; private Preference mResetButton; - private Intent mSpecialIntent; - private CstorAddCredentialHelper mCstorAddCredentialHelper; + private Intent mExternalIntent; - void handleCstorIntents(Intent intent) { + CstorHelper() { + mState = mKeyStore.test(); + } + + void handleIntent(Intent intent) { if (intent == null) return; String action = intent.getAction(); - if (CertTool.ACTION_ADD_CREDENTIAL.equals(action)) { - mCstorAddCredentialHelper = - new CstorAddCredentialHelper(intent); - showCstorDialog(CSTOR_NAME_CREDENTIAL_DIALOG); - } else if (Keystore.ACTION_UNLOCK_CREDENTIAL_STORAGE.equals( - action)) { - mSpecialIntent = intent; - showCstorDialog(mCstorHelper.isCstorInitialized() - ? CSTOR_UNLOCK_DIALOG - : CSTOR_INIT_DIALOG); + if (Credentials.UNLOCK_ACTION.equals(action)) { + mExternalIntent = intent; + showCstorDialog(mState == KeyStore.UNINITIALIZED + ? CSTOR_INIT_DIALOG : CSTOR_UNLOCK_DIALOG); + } else if (Credentials.SYSTEM_INSTALL_ACTION.equals(action)) { + mExternalIntent = intent; + // TODO: unlock and install. } } - void resumeStates() { - int state = mCstorHelper.getCstorState(); - mAccessCheckBox.setEnabled(state != Keystore.UNINITIALIZED); - mAccessCheckBox.setChecked(state == Keystore.UNLOCKED); - mResetButton.setEnabled(state != Keystore.UNINITIALIZED); - } + private void updatePreferences(int state) { + mAccessCheckBox.setEnabled(state != KeyStore.UNINITIALIZED); + mAccessCheckBox.setChecked(state == KeyStore.NO_ERROR); + mResetButton.setEnabled(state != KeyStore.UNINITIALIZED); - private void showCstorDialog(int dialogId) { - mDialogId = 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; + // 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(); } - } - - private int getCstorState() { - return mKeystore.getState(); - } - - private boolean isCstorUnlocked() { - return (mKeystore.getState() == Keystore.UNLOCKED); - } - - private boolean isCstorInitialized() { - return (mKeystore.getState() != Keystore.UNINITIALIZED); + // TODO: disabled? + mState = state; } private void lockCstor() { - mKeystore.lock(); - mAccessCheckBox.setChecked(false); + mKeyStore.lock(); + updatePreferences(KeyStore.LOCKED); } 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; + mKeyStore.unlock(passwd); + return mKeyStore.getLastError(); } private int changeCstorPassword(String oldPasswd, String newPasswd) { - int ret = mKeystore.changePassword(oldPasswd, newPasswd); - if (ret == -1) resetCstor(); - return ret; + mKeyStore.password(oldPasswd, newPasswd); + return mKeyStore.getLastError(); } 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(); + mKeyStore.password(passwd); + updatePreferences(KeyStore.NO_ERROR); } 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; + mKeyStore.reset(); + updatePreferences(KeyStore.UNINITIALIZED); } - 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(); + private void showCstorDialog(int dialogId) { + mDialogId = dialogId; + showDialog(dialogId); } public void onClick(DialogInterface dialog, int which) { - if (which == DialogInterface.BUTTON_NEGATIVE) { - onCancel(dialog); - return; - } + if (which == DialogInterface.BUTTON_NEGATIVE) return; switch (mDialogId) { case CSTOR_INIT_DIALOG: case CSTOR_CHANGE_PASSWORD_DIALOG: - mConfirm = checkPasswords((Dialog) dialog); + mRetry = !checkPasswords((Dialog) dialog); break; case CSTOR_UNLOCK_DIALOG: - mConfirm = checkUnlockPassword((Dialog) dialog); + mRetry = !checkPassword((Dialog) dialog); break; case CSTOR_RESET_DIALOG: resetCstor(); break; - - case CSTOR_NAME_CREDENTIAL_DIALOG: - mConfirm = checkAddCredential(); - break; } } public void onDismiss(DialogInterface dialog) { - if (!mConfirm) { - mConfirm = true; + if (mRetry) { showCstorDialog(mDialogId); } else { - if (mDialogId == CSTOR_UNLOCK_DIALOG) { - mAccessCheckBox.setChecked(isCstorUnlocked()); - } + removeDialog(mDialogId); - if (mCstorAddCredentialHelper != null) { - if (!isCstorInitialized()) { - showCstorDialog(CSTOR_INIT_DIALOG); - } else if (!isCstorUnlocked()) { - showCstorDialog(CSTOR_UNLOCK_DIALOG); + if (mExternalIntent != null) { + if (Credentials.SYSTEM_INSTALL_ACTION.equals( + mExternalIntent.getAction())) { + // TODO: install if unlocked. } else { - if (addCredential()) { - // succeeded - finish(); - } else { - // failed - if (mDialogId != CSTOR_NAME_CREDENTIAL_DIALOG) { - removeDialog(mDialogId); - } - showCstorDialog(CSTOR_NAME_CREDENTIAL_DIALOG); - } + finish(); } - return; - } else if (mSpecialIntent != null) { - finish(); } - removeDialog(mDialogId); } } - private void showResetWarning(int count) { - TextView v = showError(count <= 3 - ? R.string.cstor_password_error_reset_warning - : R.string.cstor_password_error); - if (count <= 3) { - if (count == 1) { - v.setText(R.string.cstor_password_error_reset_warning); - } else { - String format = getString( - R.string.cstor_password_error_reset_warning_plural); - v.setText(String.format(format, count)); - } + // returns false if there is no error. + private boolean checkError(int error) { + if (error == KeyStore.NO_ERROR) { + updatePreferences(KeyStore.NO_ERROR); + return false; } - } - - private boolean checkAddCredential() { - hideError(); - - String name = getText(R.id.cstor_credential_name); - if (TextUtils.isEmpty(name)) { - showError(R.string.cstor_name_empty_error); + if (error == KeyStore.UNINITIALIZED) { + updatePreferences(KeyStore.UNINITIALIZED); 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; - } + if (error < KeyStore.WRONG_PASSWORD) { + 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); + int count = error - KeyStore.WRONG_PASSWORD + 1; + if (count > 3) { + showError(R.string.cstor_password_error); + return true; } - - return true; - } - - // returns true if the password is long enough and does not contain - // characters that we don't like - 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; + TextView v = showError(R.string.cstor_password_error_reset_warning); + if (count == 1) { + v.setText(R.string.cstor_password_error_reset_warning); } else { - return true; + String format = getString( + R.string.cstor_password_error_reset_warning_plural); + v.setText(String.format(format, count)); } + return true; } - // returns true if the password is ok - private boolean checkUnlockPassword(Dialog d) { + // returns true if the password is correct + private boolean checkPassword(Dialog d) { hideError(); String passwd = getText(R.id.cstor_password); @@ -757,17 +623,10 @@ public class SecuritySettings extends PreferenceActivity implements return false; } - int count = unlockCstor(passwd); - if (count > 0) { - showResetWarning(count); - return false; - } else { - // done or reset - return true; - } + return !checkError(unlockCstor(passwd)); } - // returns true if the passwords are ok + // returns true if the passwords are correct private boolean checkPasswords(Dialog d) { hideError(); @@ -778,39 +637,22 @@ public class SecuritySettings extends PreferenceActivity implements if ((mDialogId == CSTOR_CHANGE_PASSWORD_DIALOG) && TextUtils.isEmpty(oldPasswd)) { showError(R.string.cstor_password_empty_error); - return false; - } - - if (TextUtils.isEmpty(newPasswd) - && TextUtils.isEmpty(confirmPasswd)) { + } else if (TextUtils.isEmpty(newPasswd) + || TextUtils.isEmpty(confirmPasswd)) { showError(R.string.cstor_passwords_empty_error); - return false; - } - - if (!verifyPassword(newPasswd)) { - return false; + } else if (newPasswd.length() < CSTOR_MIN_PASSWORD_LENGTH) { + showError(R.string.cstor_password_verification_error); } else if (!newPasswd.equals(confirmPasswd)) { 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 { + if (mDialogId == CSTOR_CHANGE_PASSWORD_DIALOG) { + return !checkError(changeCstorPassword(oldPasswd, newPasswd)); } else { - // done or reset + initCstor(newPasswd); return true; } - } else { - initCstor(newPasswd); - return true; } - } - - private void installCertFromSdCard() { - startActivity(new Intent(CertTool.ACTION_INSTALL_CERT_FROM_SDCARD)); + return false; } private TextView showError(int messageId) { @@ -820,40 +662,24 @@ public class SecuritySettings extends PreferenceActivity implements return v; } + private void hideError() { + hide(R.id.cstor_error); + } + private void hide(int viewId) { View v = mView.findViewById(viewId); if (v != null) v.setVisibility(View.GONE); } - private void hideError() { - hide(R.id.cstor_error); - } - private String getText(int viewId) { return ((TextView) mView.findViewById(viewId)).getText().toString(); } - private void setText(int viewId, String text) { - TextView v = (TextView) mView.findViewById(viewId); - if (v != null) v.setText(text); - } - - 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( + private void createPreferences(PreferenceCategory category) { + mAccessCheckBox = new CheckBoxPreference(SecuritySettings.this); + mAccessCheckBox.setTitle(R.string.cstor_access_title); + mAccessCheckBox.setSummary(R.string.cstor_access_summary); + mAccessCheckBox.setOnPreferenceChangeListener( new Preference.OnPreferenceChangeListener() { public boolean onPreferenceChange( Preference pref, Object value) { @@ -865,53 +691,48 @@ public class SecuritySettings extends PreferenceActivity implements return true; } }); - mAccessCheckBox = pref; - return pref; - } + category.addPreference(mAccessCheckBox); - 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( + Preference install = new Preference(SecuritySettings.this); + install.setTitle(R.string.cstor_cert_install_title); + install.setSummary(R.string.cstor_cert_install_summary); + install.setOnPreferenceClickListener( new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference pref) { - installCertFromSdCard(); + Credentials.getInstance().installFromSdCard( + SecuritySettings.this); return true; } }); - return pref; - } + category.addPreference(install); - private Preference createSetPasswordPreference() { - Preference pref = new Preference(SecuritySettings.this); - pref.setTitle(R.string.cstor_set_passwd_title); - pref.setSummary(R.string.cstor_set_passwd_summary); - pref.setOnPreferenceClickListener( + Preference password = new Preference(SecuritySettings.this); + password.setTitle(R.string.cstor_set_passwd_title); + password.setSummary(R.string.cstor_set_passwd_summary); + password.setOnPreferenceClickListener( new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference pref) { - showCstorDialog(isCstorInitialized() - ? CSTOR_CHANGE_PASSWORD_DIALOG - : CSTOR_INIT_DIALOG); + showCstorDialog(mState == KeyStore.UNINITIALIZED + ? CSTOR_INIT_DIALOG + : CSTOR_CHANGE_PASSWORD_DIALOG); return true; } }); - return pref; - } + category.addPreference(password); - private Preference createResetPreference() { - Preference pref = new Preference(SecuritySettings.this); - pref.setTitle(R.string.cstor_reset_title); - pref.setSummary(R.string.cstor_reset_summary); - pref.setOnPreferenceClickListener( + mResetButton = new Preference(SecuritySettings.this); + mResetButton.setTitle(R.string.cstor_reset_title); + mResetButton.setSummary(R.string.cstor_reset_summary); + mResetButton.setOnPreferenceClickListener( new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference pref) { showCstorDialog(CSTOR_RESET_DIALOG); return true; } }); - mResetButton = pref; - return pref; + category.addPreference(mResetButton); + + updatePreferences(mState); } private Dialog createUnlockDialog() { @@ -920,8 +741,7 @@ public class SecuritySettings extends PreferenceActivity implements hideError(); // show extra hint only when the action comes from outside - if ((mSpecialIntent == null) - && (mCstorAddCredentialHelper == null)) { + if (mExternalIntent == null) { 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) .setPositiveButton(android.R.string.ok, this) .setNegativeButton(android.R.string.cancel, this) - .setOnCancelListener(this) .create(); d.setOnDismissListener(this); return d; @@ -941,13 +760,6 @@ public class SecuritySettings extends PreferenceActivity implements R.layout.cstor_set_password_dialog_view, null); 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) { case CSTOR_INIT_DIALOG: 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) .setPositiveButton(android.R.string.ok, this) .setNegativeButton(android.R.string.cancel, this) - .setOnCancelListener(this) .create(); d.setOnDismissListener(this); return d; @@ -984,115 +795,5 @@ public class SecuritySettings extends PreferenceActivity implements .setNegativeButton(getString(android.R.string.cancel), this) .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(); - } } } |