Merge branch 'master' of github.com:open-keychain/open-keychain
This commit is contained in:
@@ -79,6 +79,9 @@ public final class Constants {
|
||||
|
||||
public static final int TEMPFILE_TTL = 24 * 60 * 60 * 1000; // 1 day
|
||||
|
||||
// the maximal length of plaintext to read in encrypt/decrypt text activities
|
||||
public static final int TEXT_LENGTH_LIMIT = 1024 * 50;
|
||||
|
||||
public static final String SAFESLINGER_SERVER = "safeslinger-openpgp.appspot.com";
|
||||
|
||||
public static final class Path {
|
||||
|
||||
@@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.operations;
|
||||
import android.content.Context;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.StringRes;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants.key;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
@@ -81,7 +82,7 @@ public abstract class BaseOperation <T extends Parcelable> implements Passphrase
|
||||
@NonNull
|
||||
public abstract OperationResult execute(T input, CryptoInputParcel cryptoInput);
|
||||
|
||||
public void updateProgress(int message, int current, int total) {
|
||||
public void updateProgress(@StringRes int message, int current, int total) {
|
||||
if (mProgressable != null) {
|
||||
mProgressable.setProgress(message, current, total);
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
||||
log.add(LogType.MSG_DC_CHARSET, indent, armorHeaders.charset);
|
||||
}
|
||||
if (armorHeaders.backupVersion != null) {
|
||||
log.add(LogType.MSG_DC_BACKUP_VERSION, indent, armorHeaders.backupVersion);
|
||||
log.add(LogType.MSG_DC_BACKUP_VERSION, indent, Integer.toString(armorHeaders.backupVersion));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,6 +322,29 @@ public class DecryptListFragment
|
||||
Uri uri = mCurrentInputUri;
|
||||
mCurrentInputUri = null;
|
||||
|
||||
Activity activity = getActivity();
|
||||
|
||||
boolean isSingleInput = mInputDataResults.isEmpty() && mPendingInputUris.isEmpty();
|
||||
if (isSingleInput) {
|
||||
|
||||
// there is always at least one mMetadata object, so we know this is >= 1 already
|
||||
boolean isSingleMetadata = result.mMetadata.size() == 1;
|
||||
OpenPgpMetadata metadata = result.mMetadata.get(0);
|
||||
boolean isText = "text/plain".equals(metadata.getMimeType());
|
||||
boolean isOverSized = metadata.getOriginalSize() > Constants.TEXT_LENGTH_LIMIT;
|
||||
|
||||
if (isSingleMetadata && isText && !isOverSized) {
|
||||
Intent displayTextIntent = new Intent(activity, DisplayTextActivity.class)
|
||||
.setDataAndType(result.mOutputUris.get(0), "text/plain")
|
||||
.putExtra(DisplayTextActivity.EXTRA_RESULT, result.mDecryptVerifyResult)
|
||||
.putExtra(DisplayTextActivity.EXTRA_METADATA, metadata);
|
||||
activity.startActivity(displayTextIntent);
|
||||
activity.finish();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mInputDataResults.put(uri, result);
|
||||
processResult(uri);
|
||||
|
||||
|
||||
@@ -28,9 +28,12 @@ import android.support.v4.app.Fragment;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.openintents.openpgp.OpenPgpMetadata;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
|
||||
import org.sufficientlysecure.keychain.ui.base.BaseActivity;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||
import org.sufficientlysecure.keychain.util.FileHelper;
|
||||
|
||||
public class DisplayTextActivity extends BaseActivity {
|
||||
@@ -73,6 +76,11 @@ public class DisplayTextActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
if (plaintext != null) {
|
||||
if (plaintext.length() > Constants.TEXT_LENGTH_LIMIT) {
|
||||
plaintext = plaintext.substring(0, Constants.TEXT_LENGTH_LIMIT);
|
||||
Notify.create(this, R.string.snack_text_too_long, Style.WARN).show();
|
||||
}
|
||||
|
||||
loadFragment(plaintext, result);
|
||||
} else {
|
||||
Toast.makeText(this, R.string.error_invalid_data, Toast.LENGTH_LONG).show();
|
||||
|
||||
@@ -18,14 +18,22 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.intents.OpenKeychainIntents;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||
import org.sufficientlysecure.keychain.util.FileHelper;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
public class EncryptTextActivity extends EncryptActivity {
|
||||
@@ -57,14 +65,38 @@ public class EncryptTextActivity extends EncryptActivity {
|
||||
|
||||
// When sending to OpenKeychain Encrypt via share menu
|
||||
if ("text/plain".equals(type)) {
|
||||
String sharedText = extras.getString(Intent.EXTRA_TEXT);
|
||||
if (sharedText != null) {
|
||||
// handle like normal text encryption, override action and extras to later
|
||||
// executeServiceMethod ACTION_ENCRYPT_TEXT in main actions
|
||||
extras.putString(EXTRA_TEXT, sharedText);
|
||||
}
|
||||
|
||||
Toast.makeText(this, R.string.toast_wrong_mimetype, Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
String sharedText;
|
||||
if (extras.containsKey(Intent.EXTRA_TEXT)) {
|
||||
sharedText = extras.getString(Intent.EXTRA_TEXT);
|
||||
} else if (extras.containsKey(Intent.EXTRA_STREAM)) {
|
||||
try {
|
||||
sharedText = FileHelper.readTextFromUri(this, extras.<Uri>getParcelable(Intent.EXTRA_STREAM), null);
|
||||
} catch (IOException e) {
|
||||
Toast.makeText(this, R.string.error_preparing_data, Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(this, R.string.toast_no_text, Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
if (sharedText != null) {
|
||||
if (sharedText.length() > Constants.TEXT_LENGTH_LIMIT) {
|
||||
sharedText = sharedText.substring(0, Constants.TEXT_LENGTH_LIMIT);
|
||||
Notify.create(this, R.string.snack_shared_text_too_long, Style.WARN).show();
|
||||
}
|
||||
// handle like normal text encryption, override action and extras to later
|
||||
// executeServiceMethod ACTION_ENCRYPT_TEXT in main actions
|
||||
extras.putString(EXTRA_TEXT, sharedText);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String textData = extras.getString(EXTRA_TEXT);
|
||||
|
||||
Reference in New Issue
Block a user