diff options
author | Thialfihar <thialfihar@gmail.com> | 2010-09-11 23:21:53 +0000 |
---|---|---|
committer | Thialfihar <thialfihar@gmail.com> | 2010-09-11 23:21:53 +0000 |
commit | b91f9397d9de4a6621b3d660b8bf0a6333b94f5d (patch) | |
tree | fd12291f6ec2800d0b492f8fe0fb393e3e2385a9 /src/org/thialfihar/android | |
parent | bc50ca00930a0b65bd49ea758283efa1c1644036 (diff) | |
download | open-keychain-b91f9397d9de4a6621b3d660b8bf0a6333b94f5d.tar.gz open-keychain-b91f9397d9de4a6621b3d660b8bf0a6333b94f5d.tar.bz2 open-keychain-b91f9397d9de4a6621b3d660b8bf0a6333b94f5d.zip |
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
Diffstat (limited to 'src/org/thialfihar/android')
-rw-r--r-- | src/org/thialfihar/android/apg/Apg.java | 11 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/BaseActivity.java | 40 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/Constants.java | 7 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/DecryptActivity.java | 17 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/EditKeyActivity.java | 2 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/EncryptActivity.java | 2 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/HkpKeyServer.java | 1 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/Id.java | 1 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/KeyListActivity.java | 6 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/KeyServerQueryActivity.java | 2 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/MailListActivity.java | 4 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/MainActivity.java | 2 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/PausableThread.java | 35 |
13 files changed, 97 insertions, 33 deletions
diff --git a/src/org/thialfihar/android/apg/Apg.java b/src/org/thialfihar/android/apg/Apg.java index 4db544556..3da8e3015 100644 --- a/src/org/thialfihar/android/apg/Apg.java +++ b/src/org/thialfihar/android/apg/Apg.java @@ -100,8 +100,8 @@ import android.database.sqlite.SQLiteDatabase; import android.net.Uri; import android.os.Bundle; import android.os.Environment; +import android.os.Handler; import android.view.ViewGroup; -import android.widget.Toast; public class 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_ENCRYPTION_KEY_IDS = "encryptionKeyIds"; 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_BINARY = "binary"; 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 Uri CONTENT_URI_SECRET_KEY_RINGS = @@ -1725,7 +1719,8 @@ public class Apg { public static Bundle verifyText(Context context, InputData data, OutputStream outStream, - ProgressDialogUpdater progress) + ProgressDialogUpdater progress, + PausableThread thread, Handler handler) throws IOException, GeneralException, PGPException, SignatureException { Bundle returnData = new Bundle(); diff --git a/src/org/thialfihar/android/apg/BaseActivity.java b/src/org/thialfihar/android/apg/BaseActivity.java index 9f1c7a2ae..0a755606a 100644 --- a/src/org/thialfihar/android/apg/BaseActivity.java +++ b/src/org/thialfihar/android/apg/BaseActivity.java @@ -45,7 +45,7 @@ public class BaseActivity extends Activity AskForSecretKeyPassPhrase.PassPhraseCallbackInterface { private ProgressDialog mProgressDialog = null; - private Thread mRunningThread = null; + private PausableThread mRunningThread = null; private Thread mDeletingThread = null; private long mSecretKeyId = 0; @@ -256,7 +256,7 @@ public class BaseActivity extends Activity @Override public void run() { Bundle data = new Bundle(); - data.putInt(Apg.EXTRA_STATUS, Id.message.delete_done); + data.putInt(Constants.extras.status, Id.message.delete_done); try { Apg.deleteFileSecurely(BaseActivity.this, file, BaseActivity.this); } catch (FileNotFoundException e) { @@ -323,9 +323,9 @@ public class BaseActivity extends Activity public void setProgress(int progress, int max) { Message msg = new Message(); Bundle data = new Bundle(); - data.putInt(Apg.EXTRA_STATUS, Id.message.progress_update); - data.putInt(Apg.EXTRA_PROGRESS, progress); - data.putInt(Apg.EXTRA_PROGRESS_MAX, max); + data.putInt(Constants.extras.status, Id.message.progress_update); + data.putInt(Constants.extras.progress, progress); + data.putInt(Constants.extras.progress_max, max); msg.setData(data); mHandler.sendMessage(msg); } @@ -333,10 +333,10 @@ public class BaseActivity extends Activity public void setProgress(String message, int progress, int max) { Message msg = new Message(); Bundle data = new Bundle(); - data.putInt(Apg.EXTRA_STATUS, Id.message.progress_update); - data.putString(Apg.EXTRA_MESSAGE, message); - data.putInt(Apg.EXTRA_PROGRESS, progress); - data.putInt(Apg.EXTRA_PROGRESS_MAX, max); + data.putInt(Constants.extras.status, Id.message.progress_update); + data.putString(Constants.extras.message, message); + data.putInt(Constants.extras.progress, progress); + data.putInt(Constants.extras.progress_max, max); msg.setData(data); mHandler.sendMessage(msg); } @@ -347,16 +347,16 @@ public class BaseActivity extends Activity return; } - int type = data.getInt(Apg.EXTRA_STATUS); + int type = data.getInt(Constants.extras.status); switch (type) { case Id.message.progress_update: { - String message = data.getString(Apg.EXTRA_MESSAGE); + String message = data.getString(Constants.extras.message); if (mProgressDialog != null) { if (message != null) { mProgressDialog.setMessage(message); } - mProgressDialog.setMax(data.getInt(Apg.EXTRA_PROGRESS_MAX)); - mProgressDialog.setProgress(data.getInt(Apg.EXTRA_PROGRESS)); + mProgressDialog.setMax(data.getInt(Constants.extras.progress_max)); + mProgressDialog.setProgress(data.getInt(Constants.extras.progress)); } break; } @@ -375,6 +375,10 @@ public class BaseActivity extends Activity doneCallback(msg); break; } + + default: { + break; + } } } @@ -406,8 +410,16 @@ public class BaseActivity extends Activity mHandler.sendMessage(msg); } + public PausableThread getRunningThread() { + return mRunningThread; + } + + public Handler getHandler() { + return mHandler; + } + public void startThread() { - mRunningThread = new Thread(this); + mRunningThread = new PausableThread(this); mRunningThread.start(); } diff --git a/src/org/thialfihar/android/apg/Constants.java b/src/org/thialfihar/android/apg/Constants.java index 4c34dbc62..194aedd23 100644 --- a/src/org/thialfihar/android/apg/Constants.java +++ b/src/org/thialfihar/android/apg/Constants.java @@ -40,4 +40,11 @@ public final class Constants { public static final class defaults { 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"; + } } diff --git a/src/org/thialfihar/android/apg/DecryptActivity.java b/src/org/thialfihar/android/apg/DecryptActivity.java index 5b598d725..76b84c79c 100644 --- a/src/org/thialfihar/android/apg/DecryptActivity.java +++ b/src/org/thialfihar/android/apg/DecryptActivity.java @@ -509,7 +509,7 @@ public class DecryptActivity extends BaseActivity { OutputStream out = mDataDestination.getOutputStream(this); if (mSignedOnly) { - data = Apg.verifyText(this, in, out, this); + data = Apg.verifyText(this, in, out, this, getRunningThread(), getHandler()); } else { data = Apg.decrypt(this, in, out, Apg.getCachedPassPhrase(getSecretKeyId()), this, mAssumeSymmetricEncryption); @@ -539,7 +539,7 @@ public class DecryptActivity extends BaseActivity { error = "" + e; } - data.putInt(Apg.EXTRA_STATUS, Id.message.done); + data.putInt(Constants.extras.status, Id.message.done); if (error != null) { data.putString(Apg.EXTRA_ERROR, error); @@ -549,6 +549,19 @@ public class DecryptActivity extends BaseActivity { 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 public void doneCallback(Message msg) { super.doneCallback(msg); diff --git a/src/org/thialfihar/android/apg/EditKeyActivity.java b/src/org/thialfihar/android/apg/EditKeyActivity.java index eb7a513f9..4bb8899ca 100644 --- a/src/org/thialfihar/android/apg/EditKeyActivity.java +++ b/src/org/thialfihar/android/apg/EditKeyActivity.java @@ -258,7 +258,7 @@ public class EditKeyActivity extends BaseActivity implements OnClickListener { error = "" + e; } - data.putInt(Apg.EXTRA_STATUS, Id.message.done); + data.putInt(Constants.extras.status, Id.message.done); if (error != null) { data.putString(Apg.EXTRA_ERROR, error); diff --git a/src/org/thialfihar/android/apg/EncryptActivity.java b/src/org/thialfihar/android/apg/EncryptActivity.java index cd6d53b41..48f5c9f54 100644 --- a/src/org/thialfihar/android/apg/EncryptActivity.java +++ b/src/org/thialfihar/android/apg/EncryptActivity.java @@ -701,7 +701,7 @@ public class EncryptActivity extends BaseActivity { error = "" + e; } - data.putInt(Apg.EXTRA_STATUS, Id.message.done); + data.putInt(Constants.extras.status, Id.message.done); if (error != null) { data.putString(Apg.EXTRA_ERROR, error); diff --git a/src/org/thialfihar/android/apg/HkpKeyServer.java b/src/org/thialfihar/android/apg/HkpKeyServer.java index 6890e65bc..472218096 100644 --- a/src/org/thialfihar/android/apg/HkpKeyServer.java +++ b/src/org/thialfihar/android/apg/HkpKeyServer.java @@ -132,7 +132,6 @@ public class HkpKeyServer extends KeyServer { if (e.getCode() == 404) { return results; } else { - System.out.println(e.getData()); if (e.getData().toLowerCase().contains("no keys found")) { return results; } else if (e.getData().toLowerCase().contains("too many")) { diff --git a/src/org/thialfihar/android/apg/Id.java b/src/org/thialfihar/android/apg/Id.java index 9431bc505..816e1fe8d 100644 --- a/src/org/thialfihar/android/apg/Id.java +++ b/src/org/thialfihar/android/apg/Id.java @@ -51,6 +51,7 @@ public final class Id { public static final int edit_key = 0x21070008; public static final int delete_done = 0x21070009; public static final int query_done = 0x21070010; + public static final int unknown_signature_key = 0x21070011; } public static final class request { diff --git a/src/org/thialfihar/android/apg/KeyListActivity.java b/src/org/thialfihar/android/apg/KeyListActivity.java index 2d5d0e5a5..2f9d15326 100644 --- a/src/org/thialfihar/android/apg/KeyListActivity.java +++ b/src/org/thialfihar/android/apg/KeyListActivity.java @@ -358,9 +358,9 @@ public class KeyListActivity extends BaseActivity { mImportData = null; 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 { - data.putInt(Apg.EXTRA_STATUS, Id.message.export_done); + data.putInt(Constants.extras.status, Id.message.export_done); } if (error != null) { @@ -387,7 +387,7 @@ public class KeyListActivity extends BaseActivity { Bundle data = msg.getData(); if (data != null) { - int type = data.getInt(Apg.EXTRA_STATUS); + int type = data.getInt(Constants.extras.status); switch (type) { case Id.message.import_done: { removeDialog(Id.dialog.importing); diff --git a/src/org/thialfihar/android/apg/KeyServerQueryActivity.java b/src/org/thialfihar/android/apg/KeyServerQueryActivity.java index c6b5a3865..53d6614b5 100644 --- a/src/org/thialfihar/android/apg/KeyServerQueryActivity.java +++ b/src/org/thialfihar/android/apg/KeyServerQueryActivity.java @@ -140,7 +140,7 @@ public class KeyServerQueryActivity extends BaseActivity { error = "Too many responses."; } - data.putInt(Apg.EXTRA_STATUS, Id.message.done); + data.putInt(Constants.extras.status, Id.message.done); if (error != null) { data.putString(Apg.EXTRA_ERROR, error); diff --git a/src/org/thialfihar/android/apg/MailListActivity.java b/src/org/thialfihar/android/apg/MailListActivity.java index 2becaad3c..9bcf5eaf8 100644 --- a/src/org/thialfihar/android/apg/MailListActivity.java +++ b/src/org/thialfihar/android/apg/MailListActivity.java @@ -39,6 +39,8 @@ import android.widget.TextView; public class MailListActivity extends ListActivity { LayoutInflater mInflater = null; + public static final String EXTRA_ACCOUNT = "account"; + private static class Conversation { public long id; public String subject; @@ -90,7 +92,7 @@ public class MailListActivity extends ListActivity { mConversations = new Vector<Conversation>(); 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? Uri uri = Uri.parse("content://gmail-ls/conversations/" + account); Cursor cursor = diff --git a/src/org/thialfihar/android/apg/MainActivity.java b/src/org/thialfihar/android/apg/MainActivity.java index 189455b32..5a07b0a42 100644 --- a/src/org/thialfihar/android/apg/MainActivity.java +++ b/src/org/thialfihar/android/apg/MainActivity.java @@ -117,7 +117,7 @@ public class MainActivity extends BaseActivity { public void onItemClick(AdapterView<?> arg0, View view, int index, long id) { String accountName = (String) mAccounts.getItemAtPosition(index); startActivity(new Intent(MainActivity.this, MailListActivity.class) - .putExtra(Apg.EXTRA_ACCOUNT, accountName)); + .putExtra(MailListActivity.EXTRA_ACCOUNT, accountName)); } }); registerForContextMenu(mAccounts); diff --git a/src/org/thialfihar/android/apg/PausableThread.java b/src/org/thialfihar/android/apg/PausableThread.java new file mode 100644 index 000000000..8a68c8a28 --- /dev/null +++ b/src/org/thialfihar/android/apg/PausableThread.java @@ -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; + } + } +} |