Merge pull request #64 from bcbarnes-gmx/Issue53

Implemented issue #53 - Change intent actions from extra ints to intent actions
This commit is contained in:
Dominik Schürmann 2013-07-25 06:55:05 -07:00
commit d1c1c45421
11 changed files with 48 additions and 84 deletions

View File

@ -65,27 +65,26 @@ public class KeychainIntentService extends IntentService implements ProgressDial
/* extras that can be given by intent */ /* extras that can be given by intent */
public static final String EXTRA_MESSENGER = "messenger"; public static final String EXTRA_MESSENGER = "messenger";
public static final String EXTRA_ACTION = "action";
public static final String EXTRA_DATA = "data"; public static final String EXTRA_DATA = "data";
/* possible EXTRA_ACTIONs */ /* possible EXTRA_ACTIONs */
public static final int ACTION_ENCRYPT_SIGN = 10; public static final String ACTION_ENCRYPT_SIGN = Constants.INTENT_PREFIX + "ENCRYPT_SIGN";
public static final int ACTION_DECRYPT_VERIFY = 20; public static final String ACTION_DECRYPT_VERIFY = Constants.INTENT_PREFIX + "DECRYPT_VERIFY";
public static final int ACTION_SAVE_KEYRING = 30; public static final String ACTION_SAVE_KEYRING = Constants.INTENT_PREFIX + "SAVE_KEYRING";
public static final int ACTION_GENERATE_KEY = 31; public static final String ACTION_GENERATE_KEY = Constants.INTENT_PREFIX + "GENERATE_KEY";
public static final int ACTION_GENERATE_DEFAULT_RSA_KEYS = 32; public static final String ACTION_GENERATE_DEFAULT_RSA_KEYS = Constants.INTENT_PREFIX + "GENERATE_DEFAULT_RSA_KEYS";
public static final int ACTION_DELETE_FILE_SECURELY = 40; public static final String ACTION_DELETE_FILE_SECURELY = Constants.INTENT_PREFIX + "DELETE_FILE_SECURELY";
public static final int ACTION_IMPORT_KEYRING = 50; public static final String ACTION_IMPORT_KEYRING = Constants.INTENT_PREFIX + "IMPORT_KEYRING";
public static final int ACTION_EXPORT_KEYRING = 51; public static final String ACTION_EXPORT_KEYRING = Constants.INTENT_PREFIX + "EXPORT_KEYRING";
public static final int ACTION_UPLOAD_KEYRING = 60; public static final String ACTION_UPLOAD_KEYRING = Constants.INTENT_PREFIX + "UPLOAD_KEYRING";
public static final int ACTION_QUERY_KEYRING = 61; public static final String ACTION_QUERY_KEYRING = Constants.INTENT_PREFIX + "QUERY_KEYRING";
public static final int ACTION_SIGN_KEYRING = 70; public static final String ACTION_SIGN_KEYRING = Constants.INTENT_PREFIX + "SIGN_KEYRING";
/* keys for data bundle */ /* keys for data bundle */
@ -216,8 +215,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
return; return;
} }
if (!(extras.containsKey(EXTRA_MESSENGER) || extras.containsKey(EXTRA_DATA) || extras if (!(extras.containsKey(EXTRA_MESSENGER) || extras.containsKey(EXTRA_DATA) ||
.containsKey(EXTRA_ACTION))) { (intent.getAction() == null))) {
Log.e(Constants.TAG, Log.e(Constants.TAG,
"Extra bundle must contain a messenger, a data bundle, and an action!"); "Extra bundle must contain a messenger, a data bundle, and an action!");
return; return;
@ -228,12 +227,10 @@ public class KeychainIntentService extends IntentService implements ProgressDial
OtherHelper.logDebugBundle(data, "EXTRA_DATA"); OtherHelper.logDebugBundle(data, "EXTRA_DATA");
int action = extras.getInt(EXTRA_ACTION); String action = intent.getAction();
// execute action from extra bundle // execute action from extra bundle
switch (action) { if( ACTION_ENCRYPT_SIGN.equals(action)) {
case ACTION_ENCRYPT_SIGN:
try { try {
/* Input */ /* Input */
int target = data.getInt(TARGET); int target = data.getInt(TARGET);
@ -382,10 +379,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
} catch (Exception e) { } catch (Exception e) {
sendErrorToHandler(e); sendErrorToHandler(e);
} }
}
break; else if(ACTION_DECRYPT_VERIFY.equals(action)) {
case ACTION_DECRYPT_VERIFY:
try { try {
/* Input */ /* Input */
int target = data.getInt(TARGET); int target = data.getInt(TARGET);
@ -514,11 +509,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
} catch (Exception e) { } catch (Exception e) {
sendErrorToHandler(e); sendErrorToHandler(e);
} }
}
break; else if(ACTION_SAVE_KEYRING.equals(action)) {
case ACTION_SAVE_KEYRING:
try { try {
/* Input */ /* Input */
String oldPassPhrase = data.getString(SAVE_KEYRING_CURRENT_PASSPHRASE); String oldPassPhrase = data.getString(SAVE_KEYRING_CURRENT_PASSPHRASE);
@ -554,11 +546,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
} catch (Exception e) { } catch (Exception e) {
sendErrorToHandler(e); sendErrorToHandler(e);
} }
}
break; else if(ACTION_GENERATE_KEY.equals(action)) {
case ACTION_GENERATE_KEY:
try { try {
/* Input */ /* Input */
int algorithm = data.getInt(GENERATE_KEY_ALGORITHM); int algorithm = data.getInt(GENERATE_KEY_ALGORITHM);
@ -585,10 +574,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
} catch (Exception e) { } catch (Exception e) {
sendErrorToHandler(e); sendErrorToHandler(e);
} }
}
break; else if(ACTION_GENERATE_DEFAULT_RSA_KEYS.equals(action)) {
case ACTION_GENERATE_DEFAULT_RSA_KEYS:
// generate one RSA 2048 key for signing and one subkey for encrypting! // generate one RSA 2048 key for signing and one subkey for encrypting!
try { try {
/* Input */ /* Input */
@ -614,10 +601,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
} catch (Exception e) { } catch (Exception e) {
sendErrorToHandler(e); sendErrorToHandler(e);
} }
}
break; else if(ACTION_DELETE_FILE_SECURELY.equals(action)) {
case ACTION_DELETE_FILE_SECURELY:
try { try {
/* Input */ /* Input */
String deleteFile = data.getString(DELETE_FILE); String deleteFile = data.getString(DELETE_FILE);
@ -638,10 +623,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
} catch (Exception e) { } catch (Exception e) {
sendErrorToHandler(e); sendErrorToHandler(e);
} }
}
break; else if(ACTION_IMPORT_KEYRING.equals(action)) {
case ACTION_IMPORT_KEYRING:
try { try {
/* Input */ /* Input */
@ -688,10 +671,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
} catch (Exception e) { } catch (Exception e) {
sendErrorToHandler(e); sendErrorToHandler(e);
} }
}
break; else if(ACTION_EXPORT_KEYRING.equals(action)) {
case ACTION_EXPORT_KEYRING:
try { try {
/* Input */ /* Input */
@ -739,10 +720,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
} catch (Exception e) { } catch (Exception e) {
sendErrorToHandler(e); sendErrorToHandler(e);
} }
}
break; else if(ACTION_UPLOAD_KEYRING.equals(action)) {
case ACTION_UPLOAD_KEYRING:
try { try {
/* Input */ /* Input */
@ -766,10 +745,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
} catch (Exception e) { } catch (Exception e) {
sendErrorToHandler(e); sendErrorToHandler(e);
} }
}
break; else if(ACTION_QUERY_KEYRING.equals(action)) {
case ACTION_QUERY_KEYRING:
try { try {
/* Input */ /* Input */
@ -797,10 +774,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
} catch (Exception e) { } catch (Exception e) {
sendErrorToHandler(e); sendErrorToHandler(e);
} }
}
break; else if(ACTION_SIGN_KEYRING.equals(action)) {
case ACTION_SIGN_KEYRING:
try { try {
/* Input */ /* Input */
@ -824,13 +799,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial
} catch (Exception e) { } catch (Exception e) {
sendErrorToHandler(e); sendErrorToHandler(e);
} }
break;
default:
break;
} }
} }
private void sendErrorToHandler(Exception e) { private void sendErrorToHandler(Exception e) {

View File

@ -758,7 +758,7 @@ public class DecryptActivity extends SherlockFragmentActivity {
// fill values for this action // fill values for this action
Bundle data = new Bundle(); Bundle data = new Bundle();
intent.putExtra(KeychainIntentService.EXTRA_ACTION, KeychainIntentService.ACTION_DECRYPT_VERIFY); intent.setAction(KeychainIntentService.ACTION_DECRYPT_VERIFY);
// choose action based on input: decrypt stream, file or bytes // choose action based on input: decrypt stream, file or bytes
if (mContentUri != null) { if (mContentUri != null) {

View File

@ -238,8 +238,7 @@ public class EditKeyActivity extends SherlockFragmentActivity {
// Send all information needed to service generate keys in other thread // Send all information needed to service generate keys in other thread
Intent serviceIntent = new Intent(this, KeychainIntentService.class); Intent serviceIntent = new Intent(this, KeychainIntentService.class);
serviceIntent.putExtra(KeychainIntentService.EXTRA_ACTION, serviceIntent.setAction(KeychainIntentService.ACTION_GENERATE_DEFAULT_RSA_KEYS);
KeychainIntentService.ACTION_GENERATE_DEFAULT_RSA_KEYS);
// fill values for this action // fill values for this action
Bundle data = new Bundle(); Bundle data = new Bundle();
@ -438,8 +437,7 @@ public class EditKeyActivity extends SherlockFragmentActivity {
// Send all information needed to service to edit key in other thread // Send all information needed to service to edit key in other thread
Intent intent = new Intent(this, KeychainIntentService.class); Intent intent = new Intent(this, KeychainIntentService.class);
intent.putExtra(KeychainIntentService.EXTRA_ACTION, intent.setAction(KeychainIntentService.ACTION_SAVE_KEYRING);
KeychainIntentService.ACTION_SAVE_KEYRING);
// fill values for this action // fill values for this action
Bundle data = new Bundle(); Bundle data = new Bundle();

View File

@ -693,7 +693,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
signOnly = (mEncryptionKeyIds == null || mEncryptionKeyIds.length == 0); signOnly = (mEncryptionKeyIds == null || mEncryptionKeyIds.length == 0);
} }
intent.putExtra(KeychainIntentService.EXTRA_ACTION, KeychainIntentService.ACTION_ENCRYPT_SIGN); intent.setAction(KeychainIntentService.ACTION_ENCRYPT_SIGN);
// choose default settings, target and data bundle by target // choose default settings, target and data bundle by target
if (mStreamAndReturnUri != null) { if (mStreamAndReturnUri != null) {

View File

@ -321,7 +321,7 @@ public class ImportKeysActivity extends SherlockFragmentActivity {
// Send all information needed to service to import key in other thread // Send all information needed to service to import key in other thread
Intent intent = new Intent(this, KeychainIntentService.class); Intent intent = new Intent(this, KeychainIntentService.class);
intent.putExtra(KeychainIntentService.EXTRA_ACTION, KeychainIntentService.ACTION_IMPORT_KEYRING); intent.setAction(KeychainIntentService.ACTION_IMPORT_KEYRING);
// fill values for this action // fill values for this action
Bundle data = new Bundle(); Bundle data = new Bundle();

View File

@ -259,7 +259,7 @@ public class KeyListActivity extends SherlockFragmentActivity {
// Send all information needed to service to export key in other thread // Send all information needed to service to export key in other thread
Intent intent = new Intent(this, KeychainIntentService.class); Intent intent = new Intent(this, KeychainIntentService.class);
intent.putExtra(KeychainIntentService.EXTRA_ACTION, KeychainIntentService.ACTION_EXPORT_KEYRING); intent.setAction(KeychainIntentService.ACTION_EXPORT_KEYRING);
// fill values for this action // fill values for this action
Bundle data = new Bundle(); Bundle data = new Bundle();

View File

@ -168,7 +168,7 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
// Send all information needed to service to query keys in other thread // Send all information needed to service to query keys in other thread
Intent intent = new Intent(this, KeychainIntentService.class); Intent intent = new Intent(this, KeychainIntentService.class);
intent.putExtra(KeychainIntentService.EXTRA_ACTION, KeychainIntentService.ACTION_QUERY_KEYRING); intent.setAction(KeychainIntentService.ACTION_QUERY_KEYRING);
// fill values for this action // fill values for this action
Bundle data = new Bundle(); Bundle data = new Bundle();

View File

@ -104,7 +104,7 @@ public class KeyServerUploadActivity extends SherlockFragmentActivity {
// Send all information needed to service to upload key in other thread // Send all information needed to service to upload key in other thread
Intent intent = new Intent(this, KeychainIntentService.class); Intent intent = new Intent(this, KeychainIntentService.class);
intent.putExtra(KeychainIntentService.EXTRA_ACTION, KeychainIntentService.ACTION_UPLOAD_KEYRING); intent.setAction(KeychainIntentService.ACTION_UPLOAD_KEYRING);
// fill values for this action // fill values for this action
Bundle data = new Bundle(); Bundle data = new Bundle();

View File

@ -199,8 +199,7 @@ public class SignKeyActivity extends SherlockFragmentActivity {
// Send all information needed to service to sign key in other thread // Send all information needed to service to sign key in other thread
Intent intent = new Intent(this, KeychainIntentService.class); Intent intent = new Intent(this, KeychainIntentService.class);
intent.putExtra(KeychainIntentService.EXTRA_ACTION, intent.setAction(KeychainIntentService.ACTION_SIGN_KEYRING);
KeychainIntentService.ACTION_SIGN_KEYRING);
// fill values for this action // fill values for this action
Bundle data = new Bundle(); Bundle data = new Bundle();
@ -251,8 +250,7 @@ public class SignKeyActivity extends SherlockFragmentActivity {
// Send all information needed to service to upload key in other thread // Send all information needed to service to upload key in other thread
Intent intent = new Intent(this, KeychainIntentService.class); Intent intent = new Intent(this, KeychainIntentService.class);
intent.putExtra(KeychainIntentService.EXTRA_ACTION, intent.setAction(KeychainIntentService.ACTION_UPLOAD_KEYRING);
KeychainIntentService.ACTION_UPLOAD_KEYRING);
// fill values for this action // fill values for this action
Bundle data = new Bundle(); Bundle data = new Bundle();

View File

@ -76,7 +76,7 @@ public class DeleteFileDialogFragment extends DialogFragment {
// fill values for this action // fill values for this action
Bundle data = new Bundle(); Bundle data = new Bundle();
intent.putExtra(KeychainIntentService.EXTRA_ACTION, KeychainIntentService.ACTION_DELETE_FILE_SECURELY); intent.setAction(KeychainIntentService.ACTION_DELETE_FILE_SECURELY);
data.putString(KeychainIntentService.DELETE_FILE, deleteFile); data.putString(KeychainIntentService.DELETE_FILE, deleteFile);
intent.putExtra(KeychainIntentService.EXTRA_DATA, data); intent.putExtra(KeychainIntentService.EXTRA_DATA, data);

View File

@ -289,8 +289,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
// Send all information needed to service to edit key in other thread // Send all information needed to service to edit key in other thread
Intent intent = new Intent(mActivity, KeychainIntentService.class); Intent intent = new Intent(mActivity, KeychainIntentService.class);
intent.putExtra(KeychainIntentService.EXTRA_ACTION, intent.setAction(KeychainIntentService.ACTION_GENERATE_KEY);
KeychainIntentService.ACTION_GENERATE_KEY);
// fill values for this action // fill values for this action
Bundle data = new Bundle(); Bundle data = new Bundle();