added some info about the speed of compression algorithms, mostly to warn about BZIP2, also added support for content URIs in file encrypt/decrypt activities

This commit is contained in:
Thialfihar 2010-07-05 13:22:03 +00:00
parent c1699150a8
commit ff2da0c5d1
6 changed files with 84 additions and 28 deletions

View File

@ -199,5 +199,6 @@
<uses-permission android:name="com.google.android.providers.gmail.permission.READ_GMAIL" /> <uses-permission android:name="com.google.android.providers.gmail.permission.READ_GMAIL" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.fsck.k9.permission.READ_ATTACHMENT" />
</manifest> </manifest>

View File

@ -278,4 +278,9 @@
<string name="hint_secretKeys">Private Schlüssel suchen</string> <string name="hint_secretKeys">Private Schlüssel suchen</string>
<string name="filterInfo">Filter: \"%s\"</string> <string name="filterInfo">Filter: \"%s\"</string>
<!-- misc -->
<string name="fast">schnell</string>
<string name="slow">langsam</string>
<string name="very_slow">sehr langsam</string>
</resources> </resources>

View File

@ -255,5 +255,10 @@
<string name="hint_secretKeys">Search Secret Keys</string> <string name="hint_secretKeys">Search Secret Keys</string>
<string name="filterInfo">Filter: \"%s\"</string> <string name="filterInfo">Filter: \"%s\"</string>
<!-- misc -->
<string name="fast">fast</string>
<string name="slow">slow</string>
<string name="very_slow">very slow</string>
</resources> </resources>

View File

@ -209,6 +209,10 @@ public class DecryptActivity extends BaseActivity {
mInputFilename = mIntent.getDataString().replace("file://", ""); mInputFilename = mIntent.getDataString().replace("file://", "");
mFilename.setText(mInputFilename); mFilename.setText(mInputFilename);
guessOutputFilename(); guessOutputFilename();
} else if ("content".equals(mIntent.getScheme())) {
mInputFilename = mIntent.getDataString();
mFilename.setText(mInputFilename);
guessOutputFilename();
} }
mSource.setInAnimation(null); mSource.setInAnimation(null);
mSource.setOutAnimation(null); mSource.setOutAnimation(null);
@ -363,12 +367,14 @@ public class DecryptActivity extends BaseActivity {
return; return;
} }
File file = new File(mInputFilename); if (mInputFilename.startsWith("file")) {
if (!file.exists() || !file.isFile()) { File file = new File(mInputFilename);
Toast.makeText(this, getString(R.string.errorMessage, if (!file.exists() || !file.isFile()) {
getString(R.string.error_fileNotFound)), Toast.makeText(this, getString(R.string.errorMessage,
Toast.LENGTH_SHORT).show(); getString(R.string.error_fileNotFound)),
return; Toast.LENGTH_SHORT).show();
return;
}
} }
} }
@ -388,7 +394,11 @@ public class DecryptActivity extends BaseActivity {
try { try {
InputStream in; InputStream in;
if (mDecryptTarget == Id.target.file) { if (mDecryptTarget == Id.target.file) {
in = new FileInputStream(mInputFilename); if (mInputFilename.startsWith("file")) {
in = new FileInputStream(mInputFilename);
} else {
in = getContentResolver().openInputStream(Uri.parse(mInputFilename));
}
} else { } else {
in = new ByteArrayInputStream(mMessage.getText().toString().getBytes()); in = new ByteArrayInputStream(mMessage.getText().toString().getBytes());
} }
@ -403,7 +413,11 @@ public class DecryptActivity extends BaseActivity {
// look at the file/message again to check whether there's // look at the file/message again to check whether there's
// symmetric encryption data in there // symmetric encryption data in there
if (mDecryptTarget == Id.target.file) { if (mDecryptTarget == Id.target.file) {
in = new FileInputStream(mInputFilename); if (mInputFilename.startsWith("file")) {
in = new FileInputStream(mInputFilename);
} else {
in = getContentResolver().openInputStream(Uri.parse(mInputFilename));
}
} else { } else {
in = new ByteArrayInputStream(mMessage.getText().toString().getBytes()); in = new ByteArrayInputStream(mMessage.getText().toString().getBytes());
} }
@ -488,10 +502,22 @@ public class DecryptActivity extends BaseActivity {
out = new ByteArrayOutputStream(); out = new ByteArrayOutputStream();
size = messageData.getBytes().length; size = messageData.getBytes().length;
} else { } else {
in = new PositionAwareInputStream(new FileInputStream(mInputFilename)); if (mInputFilename.startsWith("content")) {
InputStream tmp = getContentResolver().openInputStream(Uri.parse(mInputFilename));
size = 0;
long n = 0;
byte dummy[] = new byte[0x10000];
while ((n = tmp.read(dummy)) > 0) {
size += n;
}
in = new PositionAwareInputStream(
getContentResolver().openInputStream(Uri.parse(mInputFilename)));
} else {
in = new PositionAwareInputStream(new FileInputStream(mInputFilename));
File file = new File(mInputFilename);
size = file.length();
}
out = new FileOutputStream(mOutputFilename); out = new FileOutputStream(mOutputFilename);
File file = new File(mInputFilename);
size = file.length();
} }
if (mSignedOnly) { if (mSignedOnly) {

View File

@ -203,10 +203,11 @@ public class EncryptActivity extends BaseActivity {
mFileCompression = (Spinner) findViewById(R.id.fileCompression); mFileCompression = (Spinner) findViewById(R.id.fileCompression);
Choice[] choices = new Choice[] { Choice[] choices = new Choice[] {
new Choice(Id.choice.compression.none, getString(R.string.choice_none)), new Choice(Id.choice.compression.none, getString(R.string.choice_none) +
new Choice(Id.choice.compression.zip, "ZIP"), " (" + getString(R.string.fast) + ")"),
new Choice(Id.choice.compression.bzip2, "BZIP2"), new Choice(Id.choice.compression.zip, "ZIP (" + getString(R.string.fast) + ")"),
new Choice(Id.choice.compression.zlib, "ZLIB"), new Choice(Id.choice.compression.zlib, "ZLIB (" + getString(R.string.fast) + ")"),
new Choice(Id.choice.compression.bzip2, "BZIP2 (" + getString(R.string.very_slow) + ")"),
}; };
ArrayAdapter<Choice> adapter = ArrayAdapter<Choice> adapter =
new ArrayAdapter<Choice>(this, android.R.layout.simple_spinner_item, choices); new ArrayAdapter<Choice>(this, android.R.layout.simple_spinner_item, choices);
@ -470,12 +471,14 @@ public class EncryptActivity extends BaseActivity {
return; return;
} }
File file = new File(mInputFilename); if (!mInputFilename.startsWith("content")) {
if (!file.exists() || !file.isFile()) { File file = new File(mInputFilename);
Toast.makeText(this, getString(R.string.errorMessage, if (!file.exists() || !file.isFile()) {
getString(R.string.error_fileNotFound)), Toast.makeText(this, getString(R.string.errorMessage,
Toast.LENGTH_SHORT).show(); getString(R.string.error_fileNotFound)),
return; Toast.LENGTH_SHORT).show();
return;
}
} }
} }
@ -576,11 +579,22 @@ public class EncryptActivity extends BaseActivity {
} }
} }
in = new FileInputStream(mInputFilename); if (mInputFilename.startsWith("content")) {
in = getContentResolver().openInputStream(Uri.parse(mInputFilename));
size = 0;
long n = 0;
byte dummy[] = new byte[0x10000];
while ((n = in.read(dummy)) > 0) {
size += n;
}
in = getContentResolver().openInputStream(Uri.parse(mInputFilename));
} else {
in = new FileInputStream(mInputFilename);
File file = new File(mInputFilename);
size = file.length();
}
out = new FileOutputStream(mOutputFilename); out = new FileOutputStream(mOutputFilename);
File file = new File(mInputFilename);
size = file.length();
useAsciiArmour = mAsciiArmour.isChecked(); useAsciiArmour = mAsciiArmour.isChecked();
compressionId = ((Choice) mFileCompression.getSelectedItem()).getId(); compressionId = ((Choice) mFileCompression.getSelectedItem()).getId();
} else { } else {

View File

@ -18,6 +18,7 @@ package org.thialfihar.android.apg;
import org.bouncycastle2.bcpg.HashAlgorithmTags; import org.bouncycastle2.bcpg.HashAlgorithmTags;
import org.bouncycastle2.openpgp.PGPEncryptedData; import org.bouncycastle2.openpgp.PGPEncryptedData;
import org.thialfihar.android.apg.utils.Choice;
import android.os.Bundle; import android.os.Bundle;
import android.preference.CheckBoxPreference; import android.preference.CheckBoxPreference;
@ -118,12 +119,16 @@ public class PreferencesActivity extends PreferenceActivity {
mMessageCompression = (IntegerListPreference) findPreference(Constants.pref.default_message_compression); mMessageCompression = (IntegerListPreference) findPreference(Constants.pref.default_message_compression);
valueIds = new int[] { valueIds = new int[] {
Id.choice.compression.none, Id.choice.compression.zip, Id.choice.compression.none,
Id.choice.compression.bzip2, Id.choice.compression.zlib, Id.choice.compression.zip,
Id.choice.compression.zlib,
Id.choice.compression.bzip2,
}; };
entries = new String[] { entries = new String[] {
getString(R.string.choice_none), "ZIP", getString(R.string.choice_none) + " (" + getString(R.string.fast) + ")",
"BZIP2", "ZLIB", "ZIP (" + getString(R.string.fast) + ")",
"ZLIB (" + getString(R.string.fast) + ")",
"BZIP2 (" + getString(R.string.very_slow) + ")",
}; };
values = new String[valueIds.length]; values = new String[valueIds.length];
for (int i = 0; i < values.length; ++i) { for (int i = 0; i < values.length; ++i) {