mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 12:32:17 -05:00
moved some Intent extra constants into more appropriate places, some basic preparations to test thread-pausing during decryption/encryption to deal with certain situations, mainly an unknown signature key
This commit is contained in:
parent
bc50ca0093
commit
b91f9397d9
@ -100,8 +100,8 @@ import android.database.sqlite.SQLiteDatabase;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.os.Handler;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
public class Apg {
|
public class Apg {
|
||||||
private static final String mApgPackageName = "org.thialfihar.android.apg";
|
private static final String mApgPackageName = "org.thialfihar.android.apg";
|
||||||
@ -141,16 +141,10 @@ public class Apg {
|
|||||||
public static final String EXTRA_SUBJECT = "subject";
|
public static final String EXTRA_SUBJECT = "subject";
|
||||||
public static final String EXTRA_ENCRYPTION_KEY_IDS = "encryptionKeyIds";
|
public static final String EXTRA_ENCRYPTION_KEY_IDS = "encryptionKeyIds";
|
||||||
public static final String EXTRA_SELECTION = "selection";
|
public static final String EXTRA_SELECTION = "selection";
|
||||||
public static final String EXTRA_MESSAGE = "message";
|
|
||||||
public static final String EXTRA_ASCII_ARMOUR = "asciiArmour";
|
public static final String EXTRA_ASCII_ARMOUR = "asciiArmour";
|
||||||
public static final String EXTRA_BINARY = "binary";
|
public static final String EXTRA_BINARY = "binary";
|
||||||
public static final String EXTRA_KEY_SERVERS = "keyServers";
|
public static final String EXTRA_KEY_SERVERS = "keyServers";
|
||||||
|
|
||||||
public static final String EXTRA_PROGRESS = "progress";
|
|
||||||
public static final String EXTRA_PROGRESS_MAX = "max";
|
|
||||||
public static final String EXTRA_ACCOUNT = "account";
|
|
||||||
public static final String EXTRA_STATUS = "status";
|
|
||||||
|
|
||||||
public static final String AUTHORITY = DataProvider.AUTHORITY;
|
public static final String AUTHORITY = DataProvider.AUTHORITY;
|
||||||
|
|
||||||
public static final Uri CONTENT_URI_SECRET_KEY_RINGS =
|
public static final Uri CONTENT_URI_SECRET_KEY_RINGS =
|
||||||
@ -1725,7 +1719,8 @@ public class Apg {
|
|||||||
|
|
||||||
public static Bundle verifyText(Context context,
|
public static Bundle verifyText(Context context,
|
||||||
InputData data, OutputStream outStream,
|
InputData data, OutputStream outStream,
|
||||||
ProgressDialogUpdater progress)
|
ProgressDialogUpdater progress,
|
||||||
|
PausableThread thread, Handler handler)
|
||||||
throws IOException, GeneralException, PGPException, SignatureException {
|
throws IOException, GeneralException, PGPException, SignatureException {
|
||||||
Bundle returnData = new Bundle();
|
Bundle returnData = new Bundle();
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ public class BaseActivity extends Activity
|
|||||||
AskForSecretKeyPassPhrase.PassPhraseCallbackInterface {
|
AskForSecretKeyPassPhrase.PassPhraseCallbackInterface {
|
||||||
|
|
||||||
private ProgressDialog mProgressDialog = null;
|
private ProgressDialog mProgressDialog = null;
|
||||||
private Thread mRunningThread = null;
|
private PausableThread mRunningThread = null;
|
||||||
private Thread mDeletingThread = null;
|
private Thread mDeletingThread = null;
|
||||||
|
|
||||||
private long mSecretKeyId = 0;
|
private long mSecretKeyId = 0;
|
||||||
@ -256,7 +256,7 @@ public class BaseActivity extends Activity
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
data.putInt(Apg.EXTRA_STATUS, Id.message.delete_done);
|
data.putInt(Constants.extras.status, Id.message.delete_done);
|
||||||
try {
|
try {
|
||||||
Apg.deleteFileSecurely(BaseActivity.this, file, BaseActivity.this);
|
Apg.deleteFileSecurely(BaseActivity.this, file, BaseActivity.this);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
@ -323,9 +323,9 @@ public class BaseActivity extends Activity
|
|||||||
public void setProgress(int progress, int max) {
|
public void setProgress(int progress, int max) {
|
||||||
Message msg = new Message();
|
Message msg = new Message();
|
||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
data.putInt(Apg.EXTRA_STATUS, Id.message.progress_update);
|
data.putInt(Constants.extras.status, Id.message.progress_update);
|
||||||
data.putInt(Apg.EXTRA_PROGRESS, progress);
|
data.putInt(Constants.extras.progress, progress);
|
||||||
data.putInt(Apg.EXTRA_PROGRESS_MAX, max);
|
data.putInt(Constants.extras.progress_max, max);
|
||||||
msg.setData(data);
|
msg.setData(data);
|
||||||
mHandler.sendMessage(msg);
|
mHandler.sendMessage(msg);
|
||||||
}
|
}
|
||||||
@ -333,10 +333,10 @@ public class BaseActivity extends Activity
|
|||||||
public void setProgress(String message, int progress, int max) {
|
public void setProgress(String message, int progress, int max) {
|
||||||
Message msg = new Message();
|
Message msg = new Message();
|
||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
data.putInt(Apg.EXTRA_STATUS, Id.message.progress_update);
|
data.putInt(Constants.extras.status, Id.message.progress_update);
|
||||||
data.putString(Apg.EXTRA_MESSAGE, message);
|
data.putString(Constants.extras.message, message);
|
||||||
data.putInt(Apg.EXTRA_PROGRESS, progress);
|
data.putInt(Constants.extras.progress, progress);
|
||||||
data.putInt(Apg.EXTRA_PROGRESS_MAX, max);
|
data.putInt(Constants.extras.progress_max, max);
|
||||||
msg.setData(data);
|
msg.setData(data);
|
||||||
mHandler.sendMessage(msg);
|
mHandler.sendMessage(msg);
|
||||||
}
|
}
|
||||||
@ -347,16 +347,16 @@ public class BaseActivity extends Activity
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int type = data.getInt(Apg.EXTRA_STATUS);
|
int type = data.getInt(Constants.extras.status);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Id.message.progress_update: {
|
case Id.message.progress_update: {
|
||||||
String message = data.getString(Apg.EXTRA_MESSAGE);
|
String message = data.getString(Constants.extras.message);
|
||||||
if (mProgressDialog != null) {
|
if (mProgressDialog != null) {
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
mProgressDialog.setMessage(message);
|
mProgressDialog.setMessage(message);
|
||||||
}
|
}
|
||||||
mProgressDialog.setMax(data.getInt(Apg.EXTRA_PROGRESS_MAX));
|
mProgressDialog.setMax(data.getInt(Constants.extras.progress_max));
|
||||||
mProgressDialog.setProgress(data.getInt(Apg.EXTRA_PROGRESS));
|
mProgressDialog.setProgress(data.getInt(Constants.extras.progress));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -375,6 +375,10 @@ public class BaseActivity extends Activity
|
|||||||
doneCallback(msg);
|
doneCallback(msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,8 +410,16 @@ public class BaseActivity extends Activity
|
|||||||
mHandler.sendMessage(msg);
|
mHandler.sendMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PausableThread getRunningThread() {
|
||||||
|
return mRunningThread;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Handler getHandler() {
|
||||||
|
return mHandler;
|
||||||
|
}
|
||||||
|
|
||||||
public void startThread() {
|
public void startThread() {
|
||||||
mRunningThread = new Thread(this);
|
mRunningThread = new PausableThread(this);
|
||||||
mRunningThread.start();
|
mRunningThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,4 +40,11 @@ public final class Constants {
|
|||||||
public static final class defaults {
|
public static final class defaults {
|
||||||
public static final String key_servers = "pool.sks-keyservers.net, subkeys.pgp.net, pgp.mit.edu";
|
public static final String key_servers = "pool.sks-keyservers.net, subkeys.pgp.net, pgp.mit.edu";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final class extras {
|
||||||
|
public static final String progress = "progress";
|
||||||
|
public static final String progress_max = "max";
|
||||||
|
public static final String status = "status";
|
||||||
|
public static final String message = "message";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -509,7 +509,7 @@ public class DecryptActivity extends BaseActivity {
|
|||||||
OutputStream out = mDataDestination.getOutputStream(this);
|
OutputStream out = mDataDestination.getOutputStream(this);
|
||||||
|
|
||||||
if (mSignedOnly) {
|
if (mSignedOnly) {
|
||||||
data = Apg.verifyText(this, in, out, this);
|
data = Apg.verifyText(this, in, out, this, getRunningThread(), getHandler());
|
||||||
} else {
|
} else {
|
||||||
data = Apg.decrypt(this, in, out, Apg.getCachedPassPhrase(getSecretKeyId()),
|
data = Apg.decrypt(this, in, out, Apg.getCachedPassPhrase(getSecretKeyId()),
|
||||||
this, mAssumeSymmetricEncryption);
|
this, mAssumeSymmetricEncryption);
|
||||||
@ -539,7 +539,7 @@ public class DecryptActivity extends BaseActivity {
|
|||||||
error = "" + e;
|
error = "" + e;
|
||||||
}
|
}
|
||||||
|
|
||||||
data.putInt(Apg.EXTRA_STATUS, Id.message.done);
|
data.putInt(Constants.extras.status, Id.message.done);
|
||||||
|
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
data.putString(Apg.EXTRA_ERROR, error);
|
data.putString(Apg.EXTRA_ERROR, error);
|
||||||
@ -549,6 +549,19 @@ public class DecryptActivity extends BaseActivity {
|
|||||||
sendMessage(msg);
|
sendMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void handlerCallback(Message msg) {
|
||||||
|
Bundle data = msg.getData();
|
||||||
|
if (data == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.getInt(Constants.extras.status) == Id.message.unknown_signature_key) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
super.handlerCallback(msg);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doneCallback(Message msg) {
|
public void doneCallback(Message msg) {
|
||||||
super.doneCallback(msg);
|
super.doneCallback(msg);
|
||||||
|
@ -258,7 +258,7 @@ public class EditKeyActivity extends BaseActivity implements OnClickListener {
|
|||||||
error = "" + e;
|
error = "" + e;
|
||||||
}
|
}
|
||||||
|
|
||||||
data.putInt(Apg.EXTRA_STATUS, Id.message.done);
|
data.putInt(Constants.extras.status, Id.message.done);
|
||||||
|
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
data.putString(Apg.EXTRA_ERROR, error);
|
data.putString(Apg.EXTRA_ERROR, error);
|
||||||
|
@ -701,7 +701,7 @@ public class EncryptActivity extends BaseActivity {
|
|||||||
error = "" + e;
|
error = "" + e;
|
||||||
}
|
}
|
||||||
|
|
||||||
data.putInt(Apg.EXTRA_STATUS, Id.message.done);
|
data.putInt(Constants.extras.status, Id.message.done);
|
||||||
|
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
data.putString(Apg.EXTRA_ERROR, error);
|
data.putString(Apg.EXTRA_ERROR, error);
|
||||||
|
@ -132,7 +132,6 @@ public class HkpKeyServer extends KeyServer {
|
|||||||
if (e.getCode() == 404) {
|
if (e.getCode() == 404) {
|
||||||
return results;
|
return results;
|
||||||
} else {
|
} else {
|
||||||
System.out.println(e.getData());
|
|
||||||
if (e.getData().toLowerCase().contains("no keys found")) {
|
if (e.getData().toLowerCase().contains("no keys found")) {
|
||||||
return results;
|
return results;
|
||||||
} else if (e.getData().toLowerCase().contains("too many")) {
|
} else if (e.getData().toLowerCase().contains("too many")) {
|
||||||
|
@ -51,6 +51,7 @@ public final class Id {
|
|||||||
public static final int edit_key = 0x21070008;
|
public static final int edit_key = 0x21070008;
|
||||||
public static final int delete_done = 0x21070009;
|
public static final int delete_done = 0x21070009;
|
||||||
public static final int query_done = 0x21070010;
|
public static final int query_done = 0x21070010;
|
||||||
|
public static final int unknown_signature_key = 0x21070011;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class request {
|
public static final class request {
|
||||||
|
@ -358,9 +358,9 @@ public class KeyListActivity extends BaseActivity {
|
|||||||
mImportData = null;
|
mImportData = null;
|
||||||
|
|
||||||
if (mTask == Id.task.import_keys) {
|
if (mTask == Id.task.import_keys) {
|
||||||
data.putInt(Apg.EXTRA_STATUS, Id.message.import_done);
|
data.putInt(Constants.extras.status, Id.message.import_done);
|
||||||
} else {
|
} else {
|
||||||
data.putInt(Apg.EXTRA_STATUS, Id.message.export_done);
|
data.putInt(Constants.extras.status, Id.message.export_done);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
@ -387,7 +387,7 @@ public class KeyListActivity extends BaseActivity {
|
|||||||
|
|
||||||
Bundle data = msg.getData();
|
Bundle data = msg.getData();
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
int type = data.getInt(Apg.EXTRA_STATUS);
|
int type = data.getInt(Constants.extras.status);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Id.message.import_done: {
|
case Id.message.import_done: {
|
||||||
removeDialog(Id.dialog.importing);
|
removeDialog(Id.dialog.importing);
|
||||||
|
@ -140,7 +140,7 @@ public class KeyServerQueryActivity extends BaseActivity {
|
|||||||
error = "Too many responses.";
|
error = "Too many responses.";
|
||||||
}
|
}
|
||||||
|
|
||||||
data.putInt(Apg.EXTRA_STATUS, Id.message.done);
|
data.putInt(Constants.extras.status, Id.message.done);
|
||||||
|
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
data.putString(Apg.EXTRA_ERROR, error);
|
data.putString(Apg.EXTRA_ERROR, error);
|
||||||
|
@ -39,6 +39,8 @@ import android.widget.TextView;
|
|||||||
public class MailListActivity extends ListActivity {
|
public class MailListActivity extends ListActivity {
|
||||||
LayoutInflater mInflater = null;
|
LayoutInflater mInflater = null;
|
||||||
|
|
||||||
|
public static final String EXTRA_ACCOUNT = "account";
|
||||||
|
|
||||||
private static class Conversation {
|
private static class Conversation {
|
||||||
public long id;
|
public long id;
|
||||||
public String subject;
|
public String subject;
|
||||||
@ -90,7 +92,7 @@ public class MailListActivity extends ListActivity {
|
|||||||
mConversations = new Vector<Conversation>();
|
mConversations = new Vector<Conversation>();
|
||||||
mMessages = new Vector<Message>();
|
mMessages = new Vector<Message>();
|
||||||
|
|
||||||
String account = getIntent().getExtras().getString(Apg.EXTRA_ACCOUNT);
|
String account = getIntent().getExtras().getString(EXTRA_ACCOUNT);
|
||||||
// TODO: what if account is null?
|
// TODO: what if account is null?
|
||||||
Uri uri = Uri.parse("content://gmail-ls/conversations/" + account);
|
Uri uri = Uri.parse("content://gmail-ls/conversations/" + account);
|
||||||
Cursor cursor =
|
Cursor cursor =
|
||||||
|
@ -117,7 +117,7 @@ public class MainActivity extends BaseActivity {
|
|||||||
public void onItemClick(AdapterView<?> arg0, View view, int index, long id) {
|
public void onItemClick(AdapterView<?> arg0, View view, int index, long id) {
|
||||||
String accountName = (String) mAccounts.getItemAtPosition(index);
|
String accountName = (String) mAccounts.getItemAtPosition(index);
|
||||||
startActivity(new Intent(MainActivity.this, MailListActivity.class)
|
startActivity(new Intent(MainActivity.this, MailListActivity.class)
|
||||||
.putExtra(Apg.EXTRA_ACCOUNT, accountName));
|
.putExtra(MailListActivity.EXTRA_ACCOUNT, accountName));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
registerForContextMenu(mAccounts);
|
registerForContextMenu(mAccounts);
|
||||||
|
35
src/org/thialfihar/android/apg/PausableThread.java
Normal file
35
src/org/thialfihar/android/apg/PausableThread.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package org.thialfihar.android.apg;
|
||||||
|
|
||||||
|
public class PausableThread extends Thread {
|
||||||
|
private boolean mPaused = false;
|
||||||
|
|
||||||
|
public PausableThread(Runnable runnable) {
|
||||||
|
super(runnable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pause() {
|
||||||
|
synchronized (this) {
|
||||||
|
mPaused = true;
|
||||||
|
while (mPaused) {
|
||||||
|
try {
|
||||||
|
wait();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unpause() {
|
||||||
|
synchronized (this) {
|
||||||
|
mPaused = false;
|
||||||
|
notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPaused() {
|
||||||
|
synchronized (this) {
|
||||||
|
return mPaused;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user