testing thread-pausing in verifyText()

This commit is contained in:
Thialfihar 2010-09-12 19:06:26 +00:00
parent 2e981bf3db
commit 3052ae80d5
6 changed files with 70 additions and 10 deletions

View File

@ -42,6 +42,7 @@
<string name="title_keyNotFound">Key Not Found</string> <string name="title_keyNotFound">Key Not Found</string>
<string name="title_help">Getting Started</string> <string name="title_help">Getting Started</string>
<string name="title_keyServerQuery">Query Key Server</string> <string name="title_keyServerQuery">Query Key Server</string>
<string name="title_unknownSignatureKey">Unknown Signature Key</string>
<!-- section_lowerCase: capitalized words, no punctuation --> <!-- section_lowerCase: capitalized words, no punctuation -->
<string name="section_userIds">User IDs</string> <string name="section_userIds">User IDs</string>
@ -211,6 +212,7 @@
<string name="unknownSignatureKeyTouchToLookUp">Unknown signature, touch to look up key.</string> <string name="unknownSignatureKeyTouchToLookUp">Unknown signature, touch to look up key.</string>
<string name="keyEditingIsBeta">Key editing is still kind of beta.</string> <string name="keyEditingIsBeta">Key editing is still kind of beta.</string>
<string name="badKeysEncountered">%s bad secret key(s) ignored. Perhaps you exported with the option\n --export-secret-subkeys\nMake sure you export with\n --export-secret-keys\ninstead.</string> <string name="badKeysEncountered">%s bad secret key(s) ignored. Perhaps you exported with the option\n --export-secret-subkeys\nMake sure you export with\n --export-secret-keys\ninstead.</string>
<string name="lookupUnknownKey">Unknown key %s, do you want to try finding it on a keyserver?</string>
<!-- error_lowerCase: phrases, no punctuation, all lowercase, <!-- error_lowerCase: phrases, no punctuation, all lowercase,
they will be put after "errorMessage", e.g. "Error: file not found" --> they will be put after "errorMessage", e.g. "Error: file not found" -->

View File

@ -100,7 +100,7 @@ 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.os.Message;
import android.view.ViewGroup; import android.view.ViewGroup;
public class Apg { public class Apg {
@ -1717,10 +1717,9 @@ public class Apg {
return returnData; return returnData;
} }
public static Bundle verifyText(Context context, public static Bundle verifyText(BaseActivity 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();
@ -1768,6 +1767,19 @@ public class Apg {
if (signatureKeyId == 0) { if (signatureKeyId == 0) {
signatureKeyId = signature.getKeyID(); 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) { if (signatureKey == null) {
signature = null; signature = null;
} else { } else {

View File

@ -414,10 +414,6 @@ public class BaseActivity extends Activity
return mRunningThread; return mRunningThread;
} }
public Handler getHandler() {
return mHandler;
}
public void startThread() { public void startThread() {
mRunningThread = new PausableThread(this); mRunningThread = new PausableThread(this);
mRunningThread.start(); mRunningThread.start();

View File

@ -46,5 +46,6 @@ public final class Constants {
public static final String progress_max = "max"; public static final String progress_max = "max";
public static final String status = "status"; public static final String status = "status";
public static final String message = "message"; public static final String message = "message";
public static final String key_id = "keyId";
} }
} }

View File

@ -31,8 +31,10 @@ import org.bouncycastle2.openpgp.PGPException;
import org.bouncycastle2.openpgp.PGPPublicKeyRing; import org.bouncycastle2.openpgp.PGPPublicKeyRing;
import org.thialfihar.android.apg.provider.DataProvider; import org.thialfihar.android.apg.provider.DataProvider;
import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@ -92,6 +94,8 @@ public class DecryptActivity extends BaseActivity {
private DataSource mDataSource = null; private DataSource mDataSource = null;
private DataDestination mDataDestination = null; private DataDestination mDataDestination = null;
private long mUnknownSignatureKeyId = 0;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -509,7 +513,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, getRunningThread(), getHandler()); data = Apg.verifyText(this, in, out, this);
} else { } else {
data = Apg.decrypt(this, in, out, Apg.getCachedPassPhrase(getSecretKeyId()), data = Apg.decrypt(this, in, out, Apg.getCachedPassPhrase(getSecretKeyId()),
this, mAssumeSymmetricEncryption); this, mAssumeSymmetricEncryption);
@ -549,6 +553,7 @@ public class DecryptActivity extends BaseActivity {
sendMessage(msg); sendMessage(msg);
} }
@Override
public void handlerCallback(Message msg) { public void handlerCallback(Message msg) {
Bundle data = msg.getData(); Bundle data = msg.getData();
if (data == null) { if (data == null) {
@ -556,7 +561,9 @@ public class DecryptActivity extends BaseActivity {
} }
if (data.getInt(Constants.extras.status) == Id.message.unknown_signature_key) { 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); super.handlerCallback(msg);
@ -673,6 +680,14 @@ public class DecryptActivity extends BaseActivity {
return; return;
} }
case Id.request.look_up_key_id: {
PausableThread thread = getRunningThread();
if (thread != null && thread.isPaused()) {
thread.unpause();
}
return;
}
default: { default: {
break; break;
} }
@ -707,6 +722,39 @@ public class DecryptActivity extends BaseActivity {
Id.request.output_filename); 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: { default: {
break; break;
} }

View File

@ -85,6 +85,7 @@ public final class Id {
public static final int deleting = 0x21070013; public static final int deleting = 0x21070013;
public static final int help = 0x21070014; public static final int help = 0x21070014;
public static final int querying = 0x21070015; public static final int querying = 0x21070015;
public static final int lookup_unknown_key = 0x21070016;
} }
public static final class task { public static final class task {