diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2ca8d949b..92b9b170b 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -90,6 +90,7 @@
Search
Help
Key Server
+ Update
Sign
diff --git a/src/org/thialfihar/android/apg/Apg.java b/src/org/thialfihar/android/apg/Apg.java
index 6dd5b9330..06f399e84 100644
--- a/src/org/thialfihar/android/apg/Apg.java
+++ b/src/org/thialfihar/android/apg/Apg.java
@@ -115,6 +115,7 @@ public class Apg {
public static final String SELECT_PUBLIC_KEYS = "org.thialfihar.android.apg.intent.SELECT_PUBLIC_KEYS";
public static final String SELECT_SECRET_KEY = "org.thialfihar.android.apg.intent.SELECT_SECRET_KEY";
public static final String IMPORT = "org.thialfihar.android.apg.intent.IMPORT";
+ public static final String LOOK_UP_KEY_ID = "org.thialfihar.android.apg.intent.LOOK_UP_KEY_ID";
}
public static final String EXTRA_TEXT = "text";
diff --git a/src/org/thialfihar/android/apg/Id.java b/src/org/thialfihar/android/apg/Id.java
index 32febc604..341d54212 100644
--- a/src/org/thialfihar/android/apg/Id.java
+++ b/src/org/thialfihar/android/apg/Id.java
@@ -23,6 +23,7 @@ public final class Id {
public static final int export = 0x21070001;
public static final int delete = 0x21070002;
public static final int edit = 0x21070003;
+ public static final int update = 0x21070004;
public static final class option {
public static final int new_pass_phrase = 0x21070001;
@@ -58,6 +59,7 @@ public final class Id {
public static final int filename = 0x21070003;
public static final int output_filename = 0x21070004;
public static final int key_server_preference = 0x21070005;
+ public static final int look_up_key_id = 0x21070006;
}
public static final class dialog {
diff --git a/src/org/thialfihar/android/apg/KeyListActivity.java b/src/org/thialfihar/android/apg/KeyListActivity.java
index 647437d8d..a33818e59 100644
--- a/src/org/thialfihar/android/apg/KeyListActivity.java
+++ b/src/org/thialfihar/android/apg/KeyListActivity.java
@@ -98,16 +98,6 @@ public class KeyListActivity extends BaseActivity {
});
handleIntent(getIntent());
-
- Intent intent = getIntent();
- if (Apg.Intent.IMPORT.equals(intent.getAction())) {
- if ("file".equals(intent.getScheme()) && intent.getDataString() != null) {
- mImportFilename = Uri.decode(intent.getDataString().replace("file://", ""));
- } else {
- mImportData = intent.getStringExtra(Apg.EXTRA_TEXT);
- }
- importKeys();
- }
}
@Override
@@ -116,7 +106,7 @@ public class KeyListActivity extends BaseActivity {
handleIntent(intent);
}
- private void handleIntent(Intent intent) {
+ protected void handleIntent(Intent intent) {
String searchString = null;
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
searchString = intent.getStringExtra(SearchManager.QUERY);
@@ -137,6 +127,15 @@ public class KeyListActivity extends BaseActivity {
}
mListAdapter = new KeyListAdapter(this, searchString);
mList.setAdapter(mListAdapter);
+
+ if (Apg.Intent.IMPORT.equals(intent.getAction())) {
+ if ("file".equals(intent.getScheme()) && intent.getDataString() != null) {
+ mImportFilename = Uri.decode(intent.getDataString().replace("file://", ""));
+ } else {
+ mImportData = intent.getStringExtra(Apg.EXTRA_TEXT);
+ }
+ importKeys();
+ }
}
@Override
diff --git a/src/org/thialfihar/android/apg/KeyServerQueryActivity.java b/src/org/thialfihar/android/apg/KeyServerQueryActivity.java
index b1cab67ed..4ae171266 100644
--- a/src/org/thialfihar/android/apg/KeyServerQueryActivity.java
+++ b/src/org/thialfihar/android/apg/KeyServerQueryActivity.java
@@ -84,6 +84,16 @@ public class KeyServerQueryActivity extends BaseActivity {
search(query);
}
});
+
+ Intent intent = getIntent();
+ if (Apg.Intent.LOOK_UP_KEY_ID.equals(intent.getAction())) {
+ long keyId = intent.getLongExtra(Apg.EXTRA_KEY_ID, 0);
+ if (keyId != 0) {
+ String query = "0x" + Apg.keyToHex(keyId);
+ mQuery.setText(query);
+ search(query);
+ }
+ }
}
private void search(String query) {
@@ -162,7 +172,13 @@ public class KeyServerQueryActivity extends BaseActivity {
Intent intent = new Intent(this, PublicKeyListActivity.class);
intent.setAction(Apg.Intent.IMPORT);
intent.putExtra(Apg.EXTRA_TEXT, mKeyData);
- startActivity(intent);
+ Intent orgIntent = getIntent();
+ if (Apg.Intent.LOOK_UP_KEY_ID.equals(orgIntent.getAction())) {
+ setResult(RESULT_OK, intent);
+ finish();
+ } else {
+ startActivity(intent);
+ }
}
}
}
diff --git a/src/org/thialfihar/android/apg/PublicKeyListActivity.java b/src/org/thialfihar/android/apg/PublicKeyListActivity.java
index 610e23683..70e9c44af 100644
--- a/src/org/thialfihar/android/apg/PublicKeyListActivity.java
+++ b/src/org/thialfihar/android/apg/PublicKeyListActivity.java
@@ -16,12 +16,17 @@
package org.thialfihar.android.apg;
+import org.bouncycastle2.openpgp.PGPPublicKeyRing;
+
+import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
import android.widget.ExpandableListView;
+import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
public class PublicKeyListActivity extends KeyListActivity {
@Override
@@ -57,6 +62,67 @@ public class PublicKeyListActivity extends KeyListActivity {
// TODO: user id? menu.setHeaderTitle("Key");
menu.add(0, Id.menu.export, 0, R.string.menu_exportKey);
menu.add(0, Id.menu.delete, 1, R.string.menu_deleteKey);
+ menu.add(0, Id.menu.update, 1, R.string.menu_updateKey);
+ }
+ }
+
+ @Override
+ public boolean onContextItemSelected(MenuItem menuItem) {
+ ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuItem.getMenuInfo();
+ int type = ExpandableListView.getPackedPositionType(info.packedPosition);
+ int groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition);
+
+ if (type != ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
+ return super.onContextItemSelected(menuItem);
+ }
+
+ switch (menuItem.getItemId()) {
+ case Id.menu.update: {
+ mSelectedItem = groupPosition;
+ final int keyRingId = mListAdapter.getKeyRingId(groupPosition);
+ long keyId = 0;
+ Object keyRing = Apg.getKeyRing(keyRingId);
+ if (keyRing != null && keyRing instanceof PGPPublicKeyRing) {
+ keyId = Apg.getMasterKey((PGPPublicKeyRing) keyRing).getKeyID();
+ }
+ if (keyId == 0) {
+ // this shouldn't happen
+ return true;
+ }
+
+ Intent intent = new Intent(this, KeyServerQueryActivity.class);
+ intent.setAction(Apg.Intent.LOOK_UP_KEY_ID);
+ intent.putExtra(Apg.EXTRA_KEY_ID, keyId);
+ startActivityForResult(intent, Id.request.look_up_key_id);
+ return true;
+ }
+
+ default: {
+ return super.onContextItemSelected(menuItem);
+ }
+ }
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ switch (requestCode) {
+ case Id.request.look_up_key_id: {
+ if (resultCode == RESULT_CANCELED || data == null ||
+ data.getStringExtra(Apg.EXTRA_TEXT) == null) {
+ return;
+ }
+
+ Intent intent = new Intent(this, PublicKeyListActivity.class);
+ intent.setAction(Apg.Intent.IMPORT);
+ intent.putExtra(Apg.EXTRA_TEXT, data.getStringExtra(Apg.EXTRA_TEXT));
+ handleIntent(intent);
+ break;
+ }
+
+ default: {
+ super.onActivityResult(requestCode, resultCode, data);
+ break;
+ }
}
}
}