aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/thialfihar/android/apg
diff options
context:
space:
mode:
authorThialfihar <thialfihar@gmail.com>2010-09-12 19:06:26 +0000
committerThialfihar <thialfihar@gmail.com>2010-09-12 19:06:26 +0000
commit3052ae80d57d3a28a46738bfafa3557690457d28 (patch)
tree99551f6548d9b00a4ee7a623d701a953d9230cec /src/org/thialfihar/android/apg
parent2e981bf3dbcd9bb3393e18bfe0ab0067b2b3e6b7 (diff)
downloadopen-keychain-3052ae80d57d3a28a46738bfafa3557690457d28.tar.gz
open-keychain-3052ae80d57d3a28a46738bfafa3557690457d28.tar.bz2
open-keychain-3052ae80d57d3a28a46738bfafa3557690457d28.zip
testing thread-pausing in verifyText()
Diffstat (limited to 'src/org/thialfihar/android/apg')
-rw-r--r--src/org/thialfihar/android/apg/Apg.java20
-rw-r--r--src/org/thialfihar/android/apg/BaseActivity.java4
-rw-r--r--src/org/thialfihar/android/apg/Constants.java1
-rw-r--r--src/org/thialfihar/android/apg/DecryptActivity.java52
-rw-r--r--src/org/thialfihar/android/apg/Id.java1
5 files changed, 68 insertions, 10 deletions
diff --git a/src/org/thialfihar/android/apg/Apg.java b/src/org/thialfihar/android/apg/Apg.java
index 3da8e3015..91532b64f 100644
--- a/src/org/thialfihar/android/apg/Apg.java
+++ b/src/org/thialfihar/android/apg/Apg.java
@@ -100,7 +100,7 @@ import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
-import android.os.Handler;
+import android.os.Message;
import android.view.ViewGroup;
public class Apg {
@@ -1717,10 +1717,9 @@ public class Apg {
return returnData;
}
- public static Bundle verifyText(Context context,
+ public static Bundle verifyText(BaseActivity context,
InputData data, OutputStream outStream,
- ProgressDialogUpdater progress,
- PausableThread thread, Handler handler)
+ ProgressDialogUpdater progress)
throws IOException, GeneralException, PGPException, SignatureException {
Bundle returnData = new Bundle();
@@ -1769,6 +1768,19 @@ public class Apg {
signatureKeyId = signature.getKeyID();
}
if (signatureKey == null) {
+ Bundle pauseData = new Bundle();
+ pauseData.putInt(Constants.extras.status, Id.message.unknown_signature_key);
+ pauseData.putLong(Constants.extras.key_id, signatureKeyId);
+ Message msg = new Message();
+ msg.setData(pauseData);
+ context.sendMessage(msg);
+ // pause here
+ context.getRunningThread().pause();
+ // see whether the key was found in the meantime
+ signatureKey = getPublicKey(signature.getKeyID());
+ }
+
+ if (signatureKey == null) {
signature = null;
} else {
signatureKeyId = signature.getKeyID();
diff --git a/src/org/thialfihar/android/apg/BaseActivity.java b/src/org/thialfihar/android/apg/BaseActivity.java
index 0a755606a..5226b90d6 100644
--- a/src/org/thialfihar/android/apg/BaseActivity.java
+++ b/src/org/thialfihar/android/apg/BaseActivity.java
@@ -414,10 +414,6 @@ public class BaseActivity extends Activity
return mRunningThread;
}
- public Handler getHandler() {
- return mHandler;
- }
-
public void startThread() {
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 194aedd23..89751e268 100644
--- a/src/org/thialfihar/android/apg/Constants.java
+++ b/src/org/thialfihar/android/apg/Constants.java
@@ -46,5 +46,6 @@ public final class Constants {
public static final String progress_max = "max";
public static final String status = "status";
public static final String message = "message";
+ public static final String key_id = "keyId";
}
}
diff --git a/src/org/thialfihar/android/apg/DecryptActivity.java b/src/org/thialfihar/android/apg/DecryptActivity.java
index 76b84c79c..02ab2f348 100644
--- a/src/org/thialfihar/android/apg/DecryptActivity.java
+++ b/src/org/thialfihar/android/apg/DecryptActivity.java
@@ -31,8 +31,10 @@ import org.bouncycastle2.openpgp.PGPException;
import org.bouncycastle2.openpgp.PGPPublicKeyRing;
import org.thialfihar.android.apg.provider.DataProvider;
+import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
+import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
@@ -92,6 +94,8 @@ public class DecryptActivity extends BaseActivity {
private DataSource mDataSource = null;
private DataDestination mDataDestination = null;
+ private long mUnknownSignatureKeyId = 0;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -509,7 +513,7 @@ public class DecryptActivity extends BaseActivity {
OutputStream out = mDataDestination.getOutputStream(this);
if (mSignedOnly) {
- data = Apg.verifyText(this, in, out, this, getRunningThread(), getHandler());
+ data = Apg.verifyText(this, in, out, this);
} else {
data = Apg.decrypt(this, in, out, Apg.getCachedPassPhrase(getSecretKeyId()),
this, mAssumeSymmetricEncryption);
@@ -549,6 +553,7 @@ public class DecryptActivity extends BaseActivity {
sendMessage(msg);
}
+ @Override
public void handlerCallback(Message msg) {
Bundle data = msg.getData();
if (data == null) {
@@ -556,7 +561,9 @@ public class DecryptActivity extends BaseActivity {
}
if (data.getInt(Constants.extras.status) == Id.message.unknown_signature_key) {
-
+ mUnknownSignatureKeyId = data.getLong(Constants.extras.key_id);
+ showDialog(Id.dialog.lookup_unknown_key);
+ return;
}
super.handlerCallback(msg);
@@ -673,6 +680,14 @@ public class DecryptActivity extends BaseActivity {
return;
}
+ case Id.request.look_up_key_id: {
+ PausableThread thread = getRunningThread();
+ if (thread != null && thread.isPaused()) {
+ thread.unpause();
+ }
+ return;
+ }
+
default: {
break;
}
@@ -707,6 +722,39 @@ public class DecryptActivity extends BaseActivity {
Id.request.output_filename);
}
+ case Id.dialog.lookup_unknown_key: {
+ AlertDialog.Builder alert = new AlertDialog.Builder(this);
+
+ alert.setIcon(android.R.drawable.ic_dialog_alert);
+ alert.setTitle(R.string.title_unknownSignatureKey);
+ alert.setMessage(getString(R.string.lookupUnknownKey, Apg.getFingerPrint(mUnknownSignatureKeyId)));
+
+ alert.setPositiveButton(android.R.string.ok,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ removeDialog(Id.dialog.lookup_unknown_key);
+ Intent intent = new Intent(DecryptActivity.this,
+ KeyServerQueryActivity.class);
+ intent.setAction(Apg.Intent.LOOK_UP_KEY_ID);
+ intent.putExtra(Apg.EXTRA_KEY_ID, mUnknownSignatureKeyId);
+ startActivityForResult(intent, Id.request.look_up_key_id);
+ }
+ });
+ alert.setNegativeButton(android.R.string.cancel,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ removeDialog(Id.dialog.lookup_unknown_key);
+ PausableThread thread = getRunningThread();
+ if (thread != null && thread.isPaused()) {
+ thread.unpause();
+ }
+ }
+ });
+ alert.setCancelable(true);
+
+ return alert.create();
+ }
+
default: {
break;
}
diff --git a/src/org/thialfihar/android/apg/Id.java b/src/org/thialfihar/android/apg/Id.java
index 816e1fe8d..ebc1ecf87 100644
--- a/src/org/thialfihar/android/apg/Id.java
+++ b/src/org/thialfihar/android/apg/Id.java
@@ -85,6 +85,7 @@ public final class Id {
public static final int deleting = 0x21070013;
public static final int help = 0x21070014;
public static final int querying = 0x21070015;
+ public static final int lookup_unknown_key = 0x21070016;
}
public static final class task {