Files
open-keychain/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/EditKeyActivity.java

660 lines
25 KiB
Java
Raw Normal View History

2010-04-06 19:54:51 +00:00
/*
* Copyright (C) 2012-2013 Dominik Schürmann <dominik@dominikschuermann.de>
2010-04-06 19:54:51 +00:00
* Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2013-01-16 14:31:16 +01:00
package org.sufficientlysecure.keychain.ui;
2012-04-14 16:18:06 +02:00
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;
import org.spongycastle.openpgp.PGPSecretKey;
import org.spongycastle.openpgp.PGPSecretKeyRing;
2013-01-16 14:31:16 +01:00
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R;
2013-09-08 15:30:05 +02:00
import org.sufficientlysecure.keychain.helper.ActionBarHelper;
2013-09-15 15:29:38 +02:00
import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
2013-01-16 14:31:16 +01:00
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
2014-01-07 21:02:31 +01:00
import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
2013-01-16 14:31:16 +01:00
import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment;
import org.sufficientlysecure.keychain.ui.widget.KeyEditor;
import org.sufficientlysecure.keychain.ui.widget.SectionView;
import org.sufficientlysecure.keychain.ui.widget.UserIdEditor;
import org.sufficientlysecure.keychain.util.IterableIterator;
import org.sufficientlysecure.keychain.util.Log;
2012-03-11 17:33:40 +01:00
2012-04-25 15:10:12 +02:00
import android.app.ProgressDialog;
2010-04-06 19:54:51 +00:00
import android.content.Context;
import android.content.Intent;
2014-01-07 21:02:31 +01:00
import android.net.Uri;
2010-04-06 19:54:51 +00:00
import android.os.Bundle;
import android.os.Handler;
2010-04-06 19:54:51 +00:00
import android.os.Message;
2012-04-20 12:12:07 +02:00
import android.os.Messenger;
2010-04-06 19:54:51 +00:00
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
2012-04-12 19:44:00 +02:00
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
2010-04-06 19:54:51 +00:00
import android.widget.LinearLayout;
import android.widget.Toast;
2014-01-07 21:02:31 +01:00
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
2014-01-09 15:12:41 +01:00
import com.beardedhen.androidbootstrap.BootstrapButton;
2014-01-07 21:02:31 +01:00
public class EditKeyActivity extends KeyActivity {
2013-09-09 14:03:58 +02:00
// Actions for internal use only:
public static final String ACTION_CREATE_KEY = Constants.INTENT_PREFIX + "CREATE_KEY";
public static final String ACTION_EDIT_KEY = Constants.INTENT_PREFIX + "EDIT_KEY";
// possible extra keys
2013-09-09 14:03:58 +02:00
public static final String EXTRA_USER_IDS = "user_ids";
public static final String EXTRA_NO_PASSPHRASE = "no_passphrase";
public static final String EXTRA_GENERATE_DEFAULT_KEYS = "generate_default_keys";
2012-12-12 19:14:09 +01:00
// results when saving key
2013-09-09 14:03:58 +02:00
public static final String RESULT_EXTRA_MASTER_KEY_ID = "master_key_id";
public static final String RESULT_EXTRA_USER_ID = "user_id";
2012-12-12 19:14:09 +01:00
2014-01-07 21:02:31 +01:00
// EDIT
private Uri mDataUri;
2010-04-06 19:54:51 +00:00
private PGPSecretKeyRing mKeyRing = null;
2012-04-25 17:54:02 +02:00
private SectionView mUserIdsView;
private SectionView mKeysView;
2010-04-06 19:54:51 +00:00
private String mCurrentPassPhrase = null;
2010-04-06 19:54:51 +00:00
private String mNewPassPhrase = null;
2014-01-09 15:12:41 +01:00
private BootstrapButton mChangePassPhrase;
private CheckBox mNoPassphrase;
2012-04-25 17:54:02 +02:00
Vector<String> mUserIds;
Vector<PGPSecretKey> mKeys;
Vector<Integer> mKeysUsages;
boolean masterCanSign = true;
2012-04-25 15:10:12 +02:00
2010-04-06 19:54:51 +00:00
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
2012-11-16 02:34:21 +01:00
2012-04-25 17:54:02 +02:00
mUserIds = new Vector<String>();
mKeys = new Vector<PGPSecretKey>();
mKeysUsages = new Vector<Integer>();
2010-04-06 19:54:51 +00:00
// Catch Intents opened from other apps
Intent intent = getIntent();
String action = intent.getAction();
if (ACTION_CREATE_KEY.equals(action)) {
handleActionCreateKey(intent);
} else if (ACTION_EDIT_KEY.equals(action)) {
handleActionEditKey(intent);
2012-04-12 15:23:00 +02:00
}
2012-04-25 17:54:02 +02:00
}
/**
* Handle intent action to create new key
*
* @param intent
*/
private void handleActionCreateKey(Intent intent) {
2014-01-07 21:02:31 +01:00
// Inflate a "Done"/"Cancel" custom action bar
ActionBarHelper.setDoneCancelView(getSupportActionBar(), R.string.btn_save,
new View.OnClickListener() {
@Override
public void onClick(View v) {
saveClicked();
}
}, R.string.btn_do_not_save, new View.OnClickListener() {
@Override
public void onClick(View v) {
cancelClicked();
}
});
Bundle extras = intent.getExtras();
mCurrentPassPhrase = "";
if (extras != null) {
// if userId is given, prefill the fields
if (extras.containsKey(EXTRA_USER_IDS)) {
Log.d(Constants.TAG, "UserIds are given!");
mUserIds.add(extras.getString(EXTRA_USER_IDS));
}
// if no passphrase is given
if (extras.containsKey(EXTRA_NO_PASSPHRASE)) {
boolean noPassphrase = extras.getBoolean(EXTRA_NO_PASSPHRASE);
if (noPassphrase) {
// check "no passphrase" checkbox and remove button
mNoPassphrase.setChecked(true);
mChangePassPhrase.setVisibility(View.GONE);
}
}
// generate key
if (extras.containsKey(EXTRA_GENERATE_DEFAULT_KEYS)) {
boolean generateDefaultKeys = extras.getBoolean(EXTRA_GENERATE_DEFAULT_KEYS);
if (generateDefaultKeys) {
// Send all information needed to service generate keys in other thread
2013-01-16 14:31:16 +01:00
Intent serviceIntent = new Intent(this, KeychainIntentService.class);
serviceIntent.setAction(KeychainIntentService.ACTION_GENERATE_DEFAULT_RSA_KEYS);
// fill values for this action
Bundle data = new Bundle();
2013-01-16 14:31:16 +01:00
data.putString(KeychainIntentService.GENERATE_KEY_SYMMETRIC_PASSPHRASE,
2012-12-12 19:14:09 +01:00
mCurrentPassPhrase);
2013-01-16 14:31:16 +01:00
serviceIntent.putExtra(KeychainIntentService.EXTRA_DATA, data);
// Message is received after generating is done in ApgService
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
this, R.string.progress_generating, ProgressDialog.STYLE_SPINNER) {
public void handleMessage(Message message) {
// handle messages by standard ApgHandler first
super.handleMessage(message);
2013-01-16 14:31:16 +01:00
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
// get new key from data bundle returned from service
Bundle data = message.getData();
2013-01-16 14:31:16 +01:00
PGPSecretKeyRing masterKeyRing = (PGPSecretKeyRing) PgpConversionHelper
.BytesToPGPKeyRing(data
2013-01-16 14:31:16 +01:00
.getByteArray(KeychainIntentService.RESULT_NEW_KEY));
PGPSecretKeyRing subKeyRing = (PGPSecretKeyRing) PgpConversionHelper
.BytesToPGPKeyRing(data
2013-01-16 14:31:16 +01:00
.getByteArray(KeychainIntentService.RESULT_NEW_KEY2));
// add master key
@SuppressWarnings("unchecked")
Iterator<PGPSecretKey> masterIt = masterKeyRing.getSecretKeys();
mKeys.add(masterIt.next());
mKeysUsages.add(Id.choice.usage.sign_only);
// add sub key
@SuppressWarnings("unchecked")
Iterator<PGPSecretKey> subIt = subKeyRing.getSecretKeys();
subIt.next(); // masterkey
mKeys.add(subIt.next());
mKeysUsages.add(Id.choice.usage.encrypt_only);
buildLayout();
}
};
};
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(saveHandler);
2013-01-16 14:31:16 +01:00
serviceIntent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
saveHandler.showProgressDialog(this);
// start service with intent
startService(serviceIntent);
}
}
2014-01-07 21:02:31 +01:00
} else {
buildLayout();
}
}
/**
* Handle intent action to edit existing key
*
* @param intent
*/
private void handleActionEditKey(Intent intent) {
// Inflate a "Done"/"Cancel" custom action bar
ActionBarHelper.setDoneView(getSupportActionBar(), R.string.btn_save,
new View.OnClickListener() {
@Override
public void onClick(View v) {
saveClicked();
}
});
mDataUri = intent.getData();
if (mDataUri == null) {
Log.e(Constants.TAG, "Intent data missing. Should be Uri of key!");
finish();
return;
} else {
Log.d(Constants.TAG, "uri: " + mDataUri);
long keyRingRowId = Long.valueOf(mDataUri.getLastPathSegment());
// get master key id using row id
long masterKeyId = ProviderHelper.getSecretMasterKeyId(this, keyRingRowId);
boolean masterCanSign = ProviderHelper.getSecretMasterKeyCanSign(this, keyRingRowId);
String passphrase = PassphraseCacheService.getCachedPassphrase(this, masterKeyId);
if (passphrase == null) {
showPassphraseDialog(masterKeyId, masterCanSign);
} else {
// PgpMain.setEditPassPhrase(passPhrase);
mCurrentPassPhrase = passphrase;
finallyEdit(masterKeyId, masterCanSign);
}
}
}
private void showPassphraseDialog(final long masterKeyId, final boolean masterCanSign) {
// Message is received after passphrase is cached
Handler returnHandler = new Handler() {
@Override
public void handleMessage(Message message) {
if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
String passPhrase = PassphraseCacheService.getCachedPassphrase(
EditKeyActivity.this, masterKeyId);
mCurrentPassPhrase = passPhrase;
finallyEdit(masterKeyId, masterCanSign);
} else {
finish();
}
}
};
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(returnHandler);
try {
PassphraseDialogFragment passphraseDialog = PassphraseDialogFragment.newInstance(
EditKeyActivity.this, messenger, masterKeyId);
passphraseDialog.show(getSupportFragmentManager(), "passphraseDialog");
} catch (PgpGeneralException e) {
Log.d(Constants.TAG, "No passphrase for this secret key!");
// send message to handler to start encryption directly
returnHandler.sendEmptyMessage(PassphraseDialogFragment.MESSAGE_OKAY);
}
}
2014-01-07 21:02:31 +01:00
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// show menu only on edit
if (mDataUri != null) {
return super.onPrepareOptionsMenu(menu);
} else {
return false;
}
}
2014-01-07 21:02:31 +01:00
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getSupportMenuInflater().inflate(R.menu.key_edit, menu);
return true;
}
2014-01-07 21:02:31 +01:00
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_key_edit_cancel:
cancelClicked();
return true;
case R.id.menu_key_edit_export_file:
showExportKeysDialog(mDataUri, Id.type.secret_key, Constants.path.APP_DIR
+ "/secexport.asc");
return true;
case R.id.menu_key_edit_delete: {
// Message is received after key is deleted
Handler returnHandler = new Handler() {
@Override
public void handleMessage(Message message) {
if (message.what == DeleteKeyDialogFragment.MESSAGE_OKAY) {
setResult(RESULT_CANCELED);
finish();
}
}
};
2014-01-09 15:12:41 +01:00
deleteKey(mDataUri, Id.type.secret_key, returnHandler);
2014-01-07 21:02:31 +01:00
return true;
}
}
2014-01-07 21:02:31 +01:00
return super.onOptionsItemSelected(item);
}
2014-01-07 21:02:31 +01:00
@SuppressWarnings("unchecked")
private void finallyEdit(final long masterKeyId, final boolean masterCanSign) {
if (masterKeyId != 0) {
PGPSecretKey masterKey = null;
mKeyRing = ProviderHelper.getPGPSecretKeyRingByMasterKeyId(this, masterKeyId);
if (mKeyRing != null) {
masterKey = PgpKeyHelper.getMasterKey(mKeyRing);
for (PGPSecretKey key : new IterableIterator<PGPSecretKey>(mKeyRing.getSecretKeys())) {
mKeys.add(key);
mKeysUsages.add(-1); // get usage when view is created
}
} else {
Log.e(Constants.TAG, "Keyring not found with masterKeyId: " + masterKeyId);
Toast.makeText(this, R.string.error_no_secret_key_found, Toast.LENGTH_LONG).show();
}
if (masterKey != null) {
for (String userId : new IterableIterator<String>(masterKey.getUserIDs())) {
Log.d(Constants.TAG, "Added userId " + userId);
mUserIds.add(userId);
}
}
}
2014-01-02 22:45:24 +01:00
// TODO: ???
if (mCurrentPassPhrase == null) {
mCurrentPassPhrase = "";
}
2014-01-07 21:02:31 +01:00
buildLayout();
2014-01-02 22:45:24 +01:00
if (mCurrentPassPhrase.equals("")) {
// check "no passphrase" checkbox and remove button
mNoPassphrase.setChecked(true);
mChangePassPhrase.setVisibility(View.GONE);
}
}
/**
* Shows the dialog to set a new passphrase
*/
private void showSetPassphraseDialog() {
// Message is received after passphrase is cached
Handler returnHandler = new Handler() {
@Override
public void handleMessage(Message message) {
if (message.what == SetPassphraseDialogFragment.MESSAGE_OKAY) {
Bundle data = message.getData();
// set new returned passphrase!
mNewPassPhrase = data
.getString(SetPassphraseDialogFragment.MESSAGE_NEW_PASSPHRASE);
updatePassPhraseButtonText();
}
}
};
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(returnHandler);
// set title based on isPassphraseSet()
int title = -1;
if (isPassphraseSet()) {
title = R.string.title_change_pass_phrase;
} else {
title = R.string.title_set_passphrase;
}
SetPassphraseDialogFragment setPassphraseDialog = SetPassphraseDialogFragment.newInstance(
messenger, title);
setPassphraseDialog.show(getSupportFragmentManager(), "setPassphraseDialog");
}
2012-04-25 17:54:02 +02:00
/**
* Build layout based on mUserId, mKeys and mKeysUsages Vectors. It creates Views for every user
* id and key.
*/
private void buildLayout() {
setContentView(R.layout.edit_key);
// find views
2014-01-09 15:12:41 +01:00
mChangePassPhrase = (BootstrapButton) findViewById(R.id.edit_key_btn_change_pass_phrase);
mNoPassphrase = (CheckBox) findViewById(R.id.edit_key_no_passphrase);
2012-04-12 15:23:00 +02:00
// Build layout based on given userIds and keys
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
2010-04-06 19:54:51 +00:00
2012-04-12 19:44:00 +02:00
LinearLayout container = (LinearLayout) findViewById(R.id.edit_key_container);
2012-04-25 17:54:02 +02:00
mUserIdsView = (SectionView) inflater.inflate(R.layout.edit_key_section, container, false);
mUserIdsView.setType(Id.type.user_id);
mUserIdsView.setCanEdit(masterCanSign);
2012-04-25 17:54:02 +02:00
mUserIdsView.setUserIds(mUserIds);
container.addView(mUserIdsView);
mKeysView = (SectionView) inflater.inflate(R.layout.edit_key_section, container, false);
mKeysView.setType(Id.type.key);
mKeysView.setCanEdit(masterCanSign);
2012-04-25 17:54:02 +02:00
mKeysView.setKeys(mKeys, mKeysUsages);
container.addView(mKeysView);
2010-04-06 19:54:51 +00:00
updatePassPhraseButtonText();
mChangePassPhrase.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
showSetPassphraseDialog();
}
});
// disable passphrase when no passphrase checkobox is checked!
mNoPassphrase.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
// remove passphrase
mNewPassPhrase = null;
mChangePassPhrase.setVisibility(View.GONE);
} else {
mChangePassPhrase.setVisibility(View.VISIBLE);
}
}
});
2010-04-06 19:54:51 +00:00
}
private long getMasterKeyId() {
2012-04-25 17:54:02 +02:00
if (mKeysView.getEditors().getChildCount() == 0) {
return 0;
}
2012-04-25 17:54:02 +02:00
return ((KeyEditor) mKeysView.getEditors().getChildAt(0)).getValue().getKeyID();
}
public boolean isPassphraseSet() {
if (mNoPassphrase.isChecked()) {
return true;
} else if ((!mCurrentPassPhrase.equals(""))
|| (mNewPassPhrase != null && !mNewPassPhrase.equals(""))) {
return true;
} else {
return false;
}
2010-04-06 19:54:51 +00:00
}
private void saveClicked() {
2012-04-25 15:10:12 +02:00
try {
if (!isPassphraseSet()) {
throw new PgpGeneralException(this.getString(R.string.set_a_passphrase));
2012-04-20 12:12:07 +02:00
}
2012-04-25 15:10:12 +02:00
// Send all information needed to service to edit key in other thread
2013-01-16 14:31:16 +01:00
Intent intent = new Intent(this, KeychainIntentService.class);
2012-04-20 12:12:07 +02:00
intent.setAction(KeychainIntentService.ACTION_SAVE_KEYRING);
2012-04-20 12:12:07 +02:00
2012-04-25 15:10:12 +02:00
// fill values for this action
Bundle data = new Bundle();
data.putString(KeychainIntentService.SAVE_KEYRING_CURRENT_PASSPHRASE,
mCurrentPassPhrase);
2013-01-16 14:31:16 +01:00
data.putString(KeychainIntentService.SAVE_KEYRING_NEW_PASSPHRASE, mNewPassPhrase);
data.putStringArrayList(KeychainIntentService.SAVE_KEYRING_USER_IDS,
2012-12-12 19:14:09 +01:00
getUserIds(mUserIdsView));
ArrayList<PGPSecretKey> keys = getKeys(mKeysView);
2013-01-16 14:31:16 +01:00
data.putByteArray(KeychainIntentService.SAVE_KEYRING_KEYS,
PgpConversionHelper.PGPSecretKeyArrayListToBytes(keys));
data.putIntegerArrayList(KeychainIntentService.SAVE_KEYRING_KEYS_USAGES,
2012-12-12 19:14:09 +01:00
getKeysUsages(mKeysView));
2013-01-16 14:31:16 +01:00
data.putLong(KeychainIntentService.SAVE_KEYRING_MASTER_KEY_ID, getMasterKeyId());
data.putBoolean(KeychainIntentService.SAVE_KEYRING_CAN_SIGN, masterCanSign);
2012-04-25 15:10:12 +02:00
2013-01-16 14:31:16 +01:00
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
2012-04-25 15:10:12 +02:00
// Message is received after saving is done in ApgService
2013-01-16 14:31:16 +01:00
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this,
2012-11-16 02:34:21 +01:00
R.string.progress_saving, ProgressDialog.STYLE_HORIZONTAL) {
2012-04-25 15:10:12 +02:00
public void handleMessage(Message message) {
// handle messages by standard ApgHandler first
super.handleMessage(message);
2013-01-16 14:31:16 +01:00
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
2012-12-12 19:14:09 +01:00
Intent data = new Intent();
data.putExtra(RESULT_EXTRA_MASTER_KEY_ID, getMasterKeyId());
ArrayList<String> userIds = null;
try {
userIds = getUserIds(mUserIdsView);
2013-01-16 14:31:16 +01:00
} catch (PgpGeneralException e) {
2012-12-12 19:14:09 +01:00
Log.e(Constants.TAG, "exception while getting user ids", e);
}
data.putExtra(RESULT_EXTRA_USER_ID, userIds.get(0));
setResult(RESULT_OK, data);
2012-04-25 15:10:12 +02:00
finish();
}
};
};
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(saveHandler);
2013-01-16 14:31:16 +01:00
intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
2012-04-25 15:10:12 +02:00
saveHandler.showProgressDialog(this);
2012-04-20 12:12:07 +02:00
2012-04-25 15:10:12 +02:00
// start service with intent
startService(intent);
} catch (PgpGeneralException e) {
Toast.makeText(this, getString(R.string.error_message, e.getMessage()),
2012-04-25 15:10:12 +02:00
Toast.LENGTH_SHORT).show();
}
}
2012-04-20 12:12:07 +02:00
2012-12-12 19:14:09 +01:00
private void cancelClicked() {
setResult(RESULT_CANCELED);
finish();
}
2012-04-25 15:10:12 +02:00
/**
* Returns user ids from the SectionView
*
* @param userIdsView
* @return
*/
private ArrayList<String> getUserIds(SectionView userIdsView) throws PgpGeneralException {
ArrayList<String> userIds = new ArrayList<String>();
2010-04-06 19:54:51 +00:00
2012-04-20 12:12:07 +02:00
ViewGroup userIdEditors = userIdsView.getEditors();
boolean gotMainUserId = false;
for (int i = 0; i < userIdEditors.getChildCount(); ++i) {
UserIdEditor editor = (UserIdEditor) userIdEditors.getChildAt(i);
String userId = null;
try {
userId = editor.getValue();
} catch (UserIdEditor.NoNameException e) {
throw new PgpGeneralException(this.getString(R.string.error_user_id_needs_a_name));
2012-04-20 12:12:07 +02:00
} catch (UserIdEditor.NoEmailException e) {
throw new PgpGeneralException(
this.getString(R.string.error_user_id_needs_an_email_address));
2012-04-20 12:12:07 +02:00
} catch (UserIdEditor.InvalidEmailException e) {
throw new PgpGeneralException(e.getMessage());
2012-04-20 12:12:07 +02:00
}
if (userId.equals("")) {
continue;
}
if (editor.isMainUserId()) {
userIds.add(0, userId);
2012-04-20 12:12:07 +02:00
gotMainUserId = true;
} else {
userIds.add(userId);
2010-04-06 19:54:51 +00:00
}
}
2012-04-20 12:12:07 +02:00
if (userIds.size() == 0) {
throw new PgpGeneralException(getString(R.string.error_key_needs_a_user_id));
2012-04-20 12:12:07 +02:00
}
2010-04-06 19:54:51 +00:00
2012-04-20 12:12:07 +02:00
if (!gotMainUserId) {
throw new PgpGeneralException(getString(R.string.error_main_user_id_must_not_be_empty));
2010-04-06 19:54:51 +00:00
}
2012-04-20 12:12:07 +02:00
return userIds;
2010-04-06 19:54:51 +00:00
}
2012-04-25 15:10:12 +02:00
/**
* Returns keys from the SectionView
*
* @param keysView
* @return
*/
private ArrayList<PGPSecretKey> getKeys(SectionView keysView) throws PgpGeneralException {
ArrayList<PGPSecretKey> keys = new ArrayList<PGPSecretKey>();
2010-04-06 19:54:51 +00:00
2012-04-20 12:12:07 +02:00
ViewGroup keyEditors = keysView.getEditors();
2012-04-20 12:12:07 +02:00
if (keyEditors.getChildCount() == 0) {
throw new PgpGeneralException(getString(R.string.error_key_needs_master_key));
2012-04-20 12:12:07 +02:00
}
for (int i = 0; i < keyEditors.getChildCount(); ++i) {
KeyEditor editor = (KeyEditor) keyEditors.getChildAt(i);
keys.add(editor.getValue());
}
return keys;
}
2012-04-25 15:10:12 +02:00
/**
* Returns usage selections of keys from the SectionView
*
* @param keysView
* @return
*/
private ArrayList<Integer> getKeysUsages(SectionView keysView) throws PgpGeneralException {
ArrayList<Integer> getKeysUsages = new ArrayList<Integer>();
2012-04-20 12:12:07 +02:00
ViewGroup keyEditors = keysView.getEditors();
if (keyEditors.getChildCount() == 0) {
throw new PgpGeneralException(getString(R.string.error_key_needs_master_key));
}
2012-04-20 12:12:07 +02:00
for (int i = 0; i < keyEditors.getChildCount(); ++i) {
KeyEditor editor = (KeyEditor) keyEditors.getChildAt(i);
getKeysUsages.add(editor.getUsage());
}
return getKeysUsages;
2010-04-06 19:54:51 +00:00
}
private void updatePassPhraseButtonText() {
2014-01-09 15:12:41 +01:00
mChangePassPhrase.setText(isPassphraseSet() ? getString(R.string.btn_change_passphrase)
: getString(R.string.btn_set_passphrase));
}
2012-03-09 11:08:22 +01:00
}