diff options
Diffstat (limited to 'org_apg/src/org/thialfihar/android')
-rw-r--r-- | org_apg/src/org/thialfihar/android/apg/ui/DecryptActivity.java | 231 | ||||
-rw-r--r-- | org_apg/src/org/thialfihar/android/apg/ui/EncryptActivity.java | 217 |
2 files changed, 257 insertions, 191 deletions
diff --git a/org_apg/src/org/thialfihar/android/apg/ui/DecryptActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/DecryptActivity.java index e9b26935c..46bfbdfe5 100644 --- a/org_apg/src/org/thialfihar/android/apg/ui/DecryptActivity.java +++ b/org_apg/src/org/thialfihar/android/apg/ui/DecryptActivity.java @@ -58,11 +58,9 @@ import android.widget.Toast; import android.widget.ViewFlipper; import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.IOException; import java.io.InputStream; import java.util.regex.Matcher; @@ -83,8 +81,6 @@ public class DecryptActivity extends SherlockFragmentActivity { private long mSignatureKeyId = 0; - private Intent mIntent; - private boolean mReturnResult = false; private String mReplyTo = null; private String mSubject = null; @@ -253,10 +249,12 @@ public class DecryptActivity extends SherlockFragmentActivity { boolean decryptImmediately = false; - mIntent = getIntent(); + // Get intent, action and MIME type + Intent intent = getIntent(); + String action = intent.getAction(); + String type = intent.getType(); - // handled separately from other actions as it uses mIntent.setAction() - if (Intent.ACTION_VIEW.equals(mIntent.getAction())) { + if (Intent.ACTION_VIEW.equals(action)) { // TODO: old implementation of ACTION_VIEW. Is this used in K9? @@ -279,100 +277,29 @@ public class DecryptActivity extends SherlockFragmentActivity { // } // same as ACTION_DECRYPT_FILE but decrypt it immediately - mIntent.setAction(ACTION_DECRYPT_FILE); + handleActionDecryptFile(intent); decryptImmediately = true; - } - - if (ACTION_DECRYPT.equals(mIntent.getAction())) { - Log.d(Constants.TAG, "Apg Intent DECRYPT startet"); - Bundle extras = mIntent.getExtras(); - if (extras == null) { - Log.d(Constants.TAG, "extra bundle was null"); - extras = new Bundle(); - } else { - Log.d(Constants.TAG, "got extras"); - } - - mData = extras.getByteArray(EXTRA_DATA); - String textData = null; - if (mData == null) { - Log.d(Constants.TAG, "EXTRA_DATA was null"); - textData = extras.getString(EXTRA_TEXT); - } else { - Log.d(Constants.TAG, "Got data from EXTRA_DATA"); - } - if (textData != null) { - Log.d(Constants.TAG, "textData null, matching text ..."); - Matcher matcher = PGPMain.PGP_MESSAGE.matcher(textData); - if (matcher.matches()) { - Log.d(Constants.TAG, "PGP_MESSAGE matched"); - textData = matcher.group(1); - // replace non breakable spaces - textData = textData.replaceAll("\\xa0", " "); - mMessage.setText(textData); - } else { - matcher = PGPMain.PGP_SIGNED_MESSAGE.matcher(textData); - if (matcher.matches()) { - Log.d(Constants.TAG, "PGP_SIGNED_MESSAGE matched"); - textData = matcher.group(1); - // replace non breakable spaces - textData = textData.replaceAll("\\xa0", " "); - mMessage.setText(textData); - - mDecryptString = getString(R.string.btn_verify); - // build new action bar - invalidateOptionsMenu(); - } else { - Log.d(Constants.TAG, "Nothing matched!"); - } + } else if (Intent.ACTION_SEND.equals(action) && type != null) { + if ("text/plain".equals(type)) { + String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); + if (sharedText != null) { + intent.putExtra(EXTRA_TEXT, sharedText); + handleActionDecrypt(intent); + decryptImmediately = true; } - } - mReplyTo = extras.getString(EXTRA_REPLY_TO); - mSubject = extras.getString(EXTRA_SUBJECT); - } else if (ACTION_DECRYPT_FILE.equals(mIntent.getAction())) { - mInputFilename = mIntent.getData().getPath(); - mFilename.setText(mInputFilename); - guessOutputFilename(); - mSource.setInAnimation(null); - mSource.setOutAnimation(null); - while (mSource.getCurrentView().getId() != R.id.sourceFile) { - mSource.showNext(); - } - } else if (ACTION_DECRYPT_AND_RETURN.equals(mIntent.getAction())) { - mContentUri = mIntent.getData(); - Bundle extras = mIntent.getExtras(); - if (extras == null) { - extras = new Bundle(); - } - - mReturnBinary = extras.getBoolean(EXTRA_BINARY, false); + } else { + Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); + if (uri != null) { + // TODO: Implement for binary - if (mContentUri == null) { - mData = extras.getByteArray(EXTRA_DATA); - String data = extras.getString(EXTRA_TEXT); - if (data != null) { - Matcher matcher = PGPMain.PGP_MESSAGE.matcher(data); - if (matcher.matches()) { - data = matcher.group(1); - // replace non breakable spaces - data = data.replaceAll("\\xa0", " "); - mMessage.setText(data); - } else { - matcher = PGPMain.PGP_SIGNED_MESSAGE.matcher(data); - if (matcher.matches()) { - data = matcher.group(1); - // replace non breakable spaces - data = data.replaceAll("\\xa0", " "); - mMessage.setText(data); - mDecryptString = getString(R.string.btn_verify); - - // build new action bar - invalidateOptionsMenu(); - } - } } } - mReturnResult = true; + } else if (ACTION_DECRYPT.equals(action)) { + handleActionDecrypt(intent); + } else if (ACTION_DECRYPT_FILE.equals(action)) { + handleActionDecryptFile(intent); + } else if (ACTION_DECRYPT_AND_RETURN.equals(action)) { + handleActionDecryptAndReturn(intent); } if (mSource.getCurrentView().getId() == R.id.sourceMessage @@ -437,6 +364,118 @@ public class DecryptActivity extends SherlockFragmentActivity { } } + /** + * Handles activity intent with ACTION_DECRYPT + * + * @param intent + */ + private void handleActionDecrypt(Intent intent) { + Log.d(Constants.TAG, "Apg Intent DECRYPT startet"); + + Bundle extras = intent.getExtras(); + if (extras == null) { + Log.d(Constants.TAG, "extra bundle was null"); + extras = new Bundle(); + } else { + Log.d(Constants.TAG, "got extras"); + } + + mData = extras.getByteArray(EXTRA_DATA); + String textData = null; + if (mData == null) { + Log.d(Constants.TAG, "EXTRA_DATA was null"); + textData = extras.getString(EXTRA_TEXT); + } else { + Log.d(Constants.TAG, "Got data from EXTRA_DATA"); + } + if (textData != null) { + Log.d(Constants.TAG, "textData null, matching text ..."); + Matcher matcher = PGPMain.PGP_MESSAGE.matcher(textData); + if (matcher.matches()) { + Log.d(Constants.TAG, "PGP_MESSAGE matched"); + textData = matcher.group(1); + // replace non breakable spaces + textData = textData.replaceAll("\\xa0", " "); + mMessage.setText(textData); + } else { + matcher = PGPMain.PGP_SIGNED_MESSAGE.matcher(textData); + if (matcher.matches()) { + Log.d(Constants.TAG, "PGP_SIGNED_MESSAGE matched"); + textData = matcher.group(1); + // replace non breakable spaces + textData = textData.replaceAll("\\xa0", " "); + mMessage.setText(textData); + + mDecryptString = getString(R.string.btn_verify); + // build new action bar + invalidateOptionsMenu(); + } else { + Log.d(Constants.TAG, "Nothing matched!"); + } + } + } + mReplyTo = extras.getString(EXTRA_REPLY_TO); + mSubject = extras.getString(EXTRA_SUBJECT); + } + + /** + * Handles activity intent with ACTION_DECRYPT_FILE + * + * @param intent + */ + private void handleActionDecryptFile(Intent intent) { + mInputFilename = intent.getData().getPath(); + mFilename.setText(mInputFilename); + guessOutputFilename(); + mSource.setInAnimation(null); + mSource.setOutAnimation(null); + while (mSource.getCurrentView().getId() != R.id.sourceFile) { + mSource.showNext(); + } + } + + /** + * Handles activity intent with ACTION_DECRYPT_AND_RETURN + * + * @param intent + */ + private void handleActionDecryptAndReturn(Intent intent) { + mContentUri = intent.getData(); + Bundle extras = intent.getExtras(); + if (extras == null) { + extras = new Bundle(); + } + + mReturnBinary = extras.getBoolean(EXTRA_BINARY, false); + + if (mContentUri == null) { + mData = extras.getByteArray(EXTRA_DATA); + String data = extras.getString(EXTRA_TEXT); + if (data != null) { + Matcher matcher = PGPMain.PGP_MESSAGE.matcher(data); + if (matcher.matches()) { + data = matcher.group(1); + // replace non breakable spaces + data = data.replaceAll("\\xa0", " "); + mMessage.setText(data); + } else { + matcher = PGPMain.PGP_SIGNED_MESSAGE.matcher(data); + if (matcher.matches()) { + data = matcher.group(1); + // replace non breakable spaces + data = data.replaceAll("\\xa0", " "); + mMessage.setText(data); + mDecryptString = getString(R.string.btn_verify); + + // build new action bar + invalidateOptionsMenu(); + } + } + } + } + mReturnResult = true; + } + private void guessOutputFilename() { mInputFilename = mFilename.getText().toString(); File file = new File(mInputFilename); diff --git a/org_apg/src/org/thialfihar/android/apg/ui/EncryptActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/EncryptActivity.java index a65f2fc72..1e5159c98 100644 --- a/org_apg/src/org/thialfihar/android/apg/ui/EncryptActivity.java +++ b/org_apg/src/org/thialfihar/android/apg/ui/EncryptActivity.java @@ -86,7 +86,6 @@ public class EncryptActivity extends SherlockFragmentActivity { public static final String EXTRA_SIGNATURE_KEY_ID = "signatureKeyId"; public static final String EXTRA_ENCRYPTION_KEY_IDS = "encryptionKeyIds"; - private Intent mIntent = null; private String mSubject = null; private String mSendTo = null; @@ -343,104 +342,31 @@ public class EncryptActivity extends SherlockFragmentActivity { } }); - mIntent = getIntent(); - if (ACTION_ENCRYPT.equals(mIntent.getAction()) - || ACTION_ENCRYPT_FILE.equals(mIntent.getAction()) - || ACTION_ENCRYPT_AND_RETURN.equals(mIntent.getAction()) - || ACTION_GENERATE_SIGNATURE.equals(mIntent.getAction())) { - mContentUri = mIntent.getData(); - Bundle extras = mIntent.getExtras(); - if (extras == null) { - extras = new Bundle(); - } - - if (ACTION_ENCRYPT_AND_RETURN.equals(mIntent.getAction()) - || ACTION_GENERATE_SIGNATURE.equals(mIntent.getAction())) { - mReturnResult = true; - } - - if (ACTION_GENERATE_SIGNATURE.equals(mIntent.getAction())) { - mGenerateSignature = true; - mOverrideAsciiArmour = true; - mAsciiArmourDemand = false; - } - - if (extras.containsKey(EXTRA_ASCII_ARMOUR)) { - mAsciiArmourDemand = extras.getBoolean(EXTRA_ASCII_ARMOUR, true); - mOverrideAsciiArmour = true; - mAsciiArmour.setChecked(mAsciiArmourDemand); - } - - mData = extras.getByteArray(EXTRA_DATA); - String textData = null; - if (mData == null) { - textData = extras.getString(EXTRA_TEXT); - } - mSendTo = extras.getString(EXTRA_SEND_TO); - mSubject = extras.getString(EXTRA_SUBJECT); - long signatureKeyId = extras.getLong(EXTRA_SIGNATURE_KEY_ID); - long encryptionKeyIds[] = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS); - if (signatureKeyId != 0) { - PGPSecretKeyRing keyRing = PGPMain.getSecretKeyRing(signatureKeyId); - PGPSecretKey masterKey = null; - if (keyRing != null) { - masterKey = PGPHelper.getMasterKey(keyRing); - if (masterKey != null) { - Vector<PGPSecretKey> signKeys = PGPHelper.getUsableSigningKeys(keyRing); - if (signKeys.size() > 0) { - setSecretKeyId(masterKey.getKeyID()); - } - } - } - } - - if (encryptionKeyIds != null) { - Vector<Long> goodIds = new Vector<Long>(); - for (int i = 0; i < encryptionKeyIds.length; ++i) { - PGPPublicKeyRing keyRing = PGPMain.getPublicKeyRing(encryptionKeyIds[i]); - PGPPublicKey masterKey = null; - if (keyRing == null) { - continue; - } - masterKey = PGPHelper.getMasterKey(keyRing); - if (masterKey == null) { - continue; - } - Vector<PGPPublicKey> encryptKeys = PGPHelper.getUsableEncryptKeys(keyRing); - if (encryptKeys.size() == 0) { - continue; - } - goodIds.add(masterKey.getKeyID()); - } - if (goodIds.size() > 0) { - mEncryptionKeyIds = new long[goodIds.size()]; - for (int i = 0; i < goodIds.size(); ++i) { - mEncryptionKeyIds[i] = goodIds.get(i); - } + // Get intent, action and MIME type + Intent intent = getIntent(); + String action = intent.getAction(); + String type = intent.getType(); + + if (Intent.ACTION_SEND.equals(action) && type != null) { + if ("text/plain".equals(type)) { + String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); + if (sharedText != null) { + intent.setAction(ACTION_ENCRYPT); + intent.putExtra(EXTRA_TEXT, sharedText); + intent.putExtra(EXTRA_ASCII_ARMOUR, true); + handleActionEncryptSign(intent); } - } + } else { + Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); + if (uri != null) { + // TODO: Implement for binary - if (ACTION_ENCRYPT.equals(mIntent.getAction()) - || ACTION_ENCRYPT_AND_RETURN.equals(mIntent.getAction()) - || ACTION_GENERATE_SIGNATURE.equals(mIntent.getAction())) { - if (textData != null) { - mMessage.setText(textData); - } - mSource.setInAnimation(null); - mSource.setOutAnimation(null); - while (mSource.getCurrentView().getId() != R.id.sourceMessage) { - mSource.showNext(); - } - } else if (ACTION_ENCRYPT_FILE.equals(mIntent.getAction())) { - mInputFilename = mIntent.getData().getPath(); - mFilename.setText(mInputFilename); - guessOutputFilename(); - mSource.setInAnimation(null); - mSource.setOutAnimation(null); - while (mSource.getCurrentView().getId() != R.id.sourceFile) { - mSource.showNext(); } } + } else if (ACTION_ENCRYPT.equals(action) || ACTION_ENCRYPT_FILE.equals(action) + || ACTION_ENCRYPT_AND_RETURN.equals(action) + || ACTION_GENERATE_SIGNATURE.equals(action)) { + handleActionEncryptSign(intent); } updateView(); @@ -469,6 +395,107 @@ public class EncryptActivity extends SherlockFragmentActivity { } } + /** + * Handles all actions with this intent + * + * @param intent + */ + private void handleActionEncryptSign(Intent intent) { + String action = intent.getAction(); + + mContentUri = intent.getData(); + Bundle extras = intent.getExtras(); + if (extras == null) { + extras = new Bundle(); + } + + if (ACTION_ENCRYPT_AND_RETURN.equals(action) || ACTION_GENERATE_SIGNATURE.equals(action)) { + mReturnResult = true; + } + + if (ACTION_GENERATE_SIGNATURE.equals(action)) { + mGenerateSignature = true; + mOverrideAsciiArmour = true; + mAsciiArmourDemand = false; + } + + if (extras.containsKey(EXTRA_ASCII_ARMOUR)) { + mAsciiArmourDemand = extras.getBoolean(EXTRA_ASCII_ARMOUR, true); + mOverrideAsciiArmour = true; + mAsciiArmour.setChecked(mAsciiArmourDemand); + } + + mData = extras.getByteArray(EXTRA_DATA); + String textData = null; + if (mData == null) { + textData = extras.getString(EXTRA_TEXT); + } + mSendTo = extras.getString(EXTRA_SEND_TO); + mSubject = extras.getString(EXTRA_SUBJECT); + long signatureKeyId = extras.getLong(EXTRA_SIGNATURE_KEY_ID); + long encryptionKeyIds[] = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS); + if (signatureKeyId != 0) { + PGPSecretKeyRing keyRing = PGPMain.getSecretKeyRing(signatureKeyId); + PGPSecretKey masterKey = null; + if (keyRing != null) { + masterKey = PGPHelper.getMasterKey(keyRing); + if (masterKey != null) { + Vector<PGPSecretKey> signKeys = PGPHelper.getUsableSigningKeys(keyRing); + if (signKeys.size() > 0) { + setSecretKeyId(masterKey.getKeyID()); + } + } + } + } + + if (encryptionKeyIds != null) { + Vector<Long> goodIds = new Vector<Long>(); + for (int i = 0; i < encryptionKeyIds.length; ++i) { + PGPPublicKeyRing keyRing = PGPMain.getPublicKeyRing(encryptionKeyIds[i]); + PGPPublicKey masterKey = null; + if (keyRing == null) { + continue; + } + masterKey = PGPHelper.getMasterKey(keyRing); + if (masterKey == null) { + continue; + } + Vector<PGPPublicKey> encryptKeys = PGPHelper.getUsableEncryptKeys(keyRing); + if (encryptKeys.size() == 0) { + continue; + } + goodIds.add(masterKey.getKeyID()); + } + if (goodIds.size() > 0) { + mEncryptionKeyIds = new long[goodIds.size()]; + for (int i = 0; i < goodIds.size(); ++i) { + mEncryptionKeyIds[i] = goodIds.get(i); + } + } + } + + if (ACTION_ENCRYPT.equals(action) || ACTION_ENCRYPT_AND_RETURN.equals(action) + || ACTION_GENERATE_SIGNATURE.equals(action)) { + if (textData != null) { + mMessage.setText(textData); + } + mSource.setInAnimation(null); + mSource.setOutAnimation(null); + while (mSource.getCurrentView().getId() != R.id.sourceMessage) { + mSource.showNext(); + } + } else if (ACTION_ENCRYPT_FILE.equals(action)) { + mInputFilename = intent.getData().getPath(); + mFilename.setText(mInputFilename); + guessOutputFilename(); + mSource.setInAnimation(null); + mSource.setOutAnimation(null); + while (mSource.getCurrentView().getId() != R.id.sourceFile) { + mSource.showNext(); + } + } + } + private void guessOutputFilename() { mInputFilename = mFilename.getText().toString(); File file = new File(mInputFilename); |