Fix edit key intent, api improvements
This commit is contained in:
parent
39ab2c4bb0
commit
9e5aab3483
|
@ -104,7 +104,6 @@ public class KeychainIntentHelper {
|
||||||
public static final String EXTRA_SIGNATURE_UNKNOWN = "signatureUnknown";
|
public static final String EXTRA_SIGNATURE_UNKNOWN = "signatureUnknown";
|
||||||
public static final String EXTRA_USER_ID = "userId";
|
public static final String EXTRA_USER_ID = "userId";
|
||||||
public static final String EXTRA_USER_IDS = "userIds";
|
public static final String EXTRA_USER_IDS = "userIds";
|
||||||
public static final String EXTRA_KEY_ID = "masterKeyId";
|
|
||||||
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_MESSAGE = "message";
|
||||||
|
@ -123,10 +122,10 @@ public class KeychainIntentHelper {
|
||||||
|
|
||||||
public static final int DECRYPT_MESSAGE = 0x00007121;
|
public static final int DECRYPT_MESSAGE = 0x00007121;
|
||||||
public static final int ENCRYPT_MESSAGE = 0x00007122;
|
public static final int ENCRYPT_MESSAGE = 0x00007122;
|
||||||
public static final int SELECT_PUBLIC_KEYS = 0x00007123;
|
public static final int SELECT_PUBLIC_KEYRINGS = 0x00007123;
|
||||||
public static final int SELECT_SECRET_KEY = 0x00007124;
|
public static final int SELECT_SECRET_KEYRING = 0x00007124;
|
||||||
public static final int CREATE_KEY = 0x00007125;
|
public static final int CREATE_KEYRING = 0x00007125;
|
||||||
public static final int EDIT_KEY = 0x00007126;
|
public static final int EDIT_KEYRING = 0x00007126;
|
||||||
|
|
||||||
private Activity activity;
|
private Activity activity;
|
||||||
|
|
||||||
|
@ -167,6 +166,24 @@ public class KeychainIntentHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens activity to share keyring with…
|
||||||
|
*
|
||||||
|
* @return true when activity was found and executed successfully
|
||||||
|
*/
|
||||||
|
public boolean share(long masterKeyId) {
|
||||||
|
Intent intent = new Intent(ACTION_SHARE_KEYRING);
|
||||||
|
intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION);
|
||||||
|
intent.putExtra(EXTRA_MASTER_KEY_ID, masterKeyId);
|
||||||
|
try {
|
||||||
|
startActivityForResult(intent, -1);
|
||||||
|
return true;
|
||||||
|
} catch (ActivityNotFoundException e) {
|
||||||
|
activityNotFound();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens activity with qr code for masterKeyId
|
* Opens activity with qr code for masterKeyId
|
||||||
*
|
*
|
||||||
|
@ -220,7 +237,7 @@ public class KeychainIntentHelper {
|
||||||
|
|
||||||
intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION);
|
intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION);
|
||||||
try {
|
try {
|
||||||
startActivityForResult(intent, CREATE_KEY);
|
startActivityForResult(intent, CREATE_KEYRING);
|
||||||
return true;
|
return true;
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
activityNotFound();
|
activityNotFound();
|
||||||
|
@ -245,10 +262,10 @@ public class KeychainIntentHelper {
|
||||||
*/
|
*/
|
||||||
public boolean editKey(long keyId) {
|
public boolean editKey(long keyId) {
|
||||||
Intent intent = new Intent(ACTION_EDIT_KEY);
|
Intent intent = new Intent(ACTION_EDIT_KEY);
|
||||||
intent.putExtra(EXTRA_KEY_ID, keyId);
|
intent.putExtra(EXTRA_MASTER_KEY_ID, keyId);
|
||||||
intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION);
|
intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION);
|
||||||
try {
|
try {
|
||||||
startActivityForResult(intent, EDIT_KEY);
|
startActivityForResult(intent, EDIT_KEYRING);
|
||||||
return true;
|
return true;
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
activityNotFound();
|
activityNotFound();
|
||||||
|
@ -265,7 +282,7 @@ public class KeychainIntentHelper {
|
||||||
Intent intent = new Intent(ACTION_SELECT_SECRET_KEY);
|
Intent intent = new Intent(ACTION_SELECT_SECRET_KEY);
|
||||||
intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION);
|
intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION);
|
||||||
try {
|
try {
|
||||||
startActivityForResult(intent, SELECT_SECRET_KEY);
|
startActivityForResult(intent, SELECT_SECRET_KEYRING);
|
||||||
return true;
|
return true;
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
activityNotFound();
|
activityNotFound();
|
||||||
|
@ -349,7 +366,7 @@ public class KeychainIntentHelper {
|
||||||
KeychainData apgData) {
|
KeychainData apgData) {
|
||||||
|
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case CREATE_KEY:
|
case CREATE_KEYRING:
|
||||||
if (resultCode != Activity.RESULT_OK || data == null) {
|
if (resultCode != Activity.RESULT_OK || data == null) {
|
||||||
// user canceled!
|
// user canceled!
|
||||||
break;
|
break;
|
||||||
|
@ -358,16 +375,16 @@ public class KeychainIntentHelper {
|
||||||
apgData.setSecretKeyUserId(data.getStringExtra(RESULT_EXTRA_USER_ID));
|
apgData.setSecretKeyUserId(data.getStringExtra(RESULT_EXTRA_USER_ID));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SELECT_SECRET_KEY:
|
case SELECT_SECRET_KEYRING:
|
||||||
if (resultCode != Activity.RESULT_OK || data == null) {
|
if (resultCode != Activity.RESULT_OK || data == null) {
|
||||||
// user canceled!
|
// user canceled!
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
apgData.setSecretKeyId(data.getLongExtra(EXTRA_KEY_ID, 0));
|
apgData.setSecretKeyId(data.getLongExtra(EXTRA_MASTER_KEY_ID, 0));
|
||||||
apgData.setSecretKeyUserId(data.getStringExtra(EXTRA_USER_ID));
|
apgData.setSecretKeyUserId(data.getStringExtra(EXTRA_USER_ID));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SELECT_PUBLIC_KEYS:
|
case SELECT_PUBLIC_KEYRINGS:
|
||||||
if (resultCode != Activity.RESULT_OK || data == null) {
|
if (resultCode != Activity.RESULT_OK || data == null) {
|
||||||
apgData.setPublicKeyIds(null);
|
apgData.setPublicKeyIds(null);
|
||||||
break;
|
break;
|
||||||
|
@ -439,7 +456,7 @@ public class KeychainIntentHelper {
|
||||||
intent.putExtra(EXTRA_SELECTION, initialKeyIds);
|
intent.putExtra(EXTRA_SELECTION, initialKeyIds);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
startActivityForResult(intent, SELECT_PUBLIC_KEYS);
|
startActivityForResult(intent, SELECT_PUBLIC_KEYRINGS);
|
||||||
return true;
|
return true;
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
activityNotFound();
|
activityNotFound();
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||||
public static final String EXTRA_USER_IDS = "userIds";
|
public static final String EXTRA_USER_IDS = "userIds";
|
||||||
public static final String EXTRA_NO_PASSPHRASE = "noPassphrase";
|
public static final String EXTRA_NO_PASSPHRASE = "noPassphrase";
|
||||||
public static final String EXTRA_GENERATE_DEFAULT_KEYS = "generateDefaultKeys";
|
public static final String EXTRA_GENERATE_DEFAULT_KEYS = "generateDefaultKeys";
|
||||||
public static final String EXTRA_KEY_ID = "keyId";
|
public static final String EXTRA_MASTER_KEY_ID = "masterKeyId";
|
||||||
|
|
||||||
// results when saving key
|
// results when saving key
|
||||||
public static final String RESULT_EXTRA_MASTER_KEY_ID = "masterKeyId";
|
public static final String RESULT_EXTRA_MASTER_KEY_ID = "masterKeyId";
|
||||||
|
@ -317,8 +317,8 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extras != null) {
|
if (extras != null) {
|
||||||
if (extras.containsKey(EXTRA_KEY_ID)) {
|
if (extras.containsKey(EXTRA_MASTER_KEY_ID)) {
|
||||||
long keyId = extras.getLong(EXTRA_KEY_ID);
|
long keyId = extras.getLong(EXTRA_MASTER_KEY_ID);
|
||||||
|
|
||||||
if (keyId != 0) {
|
if (keyId != 0) {
|
||||||
PGPSecretKey masterKey = null;
|
PGPSecretKey masterKey = null;
|
||||||
|
|
|
@ -70,26 +70,26 @@ public class KeyListSecretActivity extends KeyListActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkPassPhraseAndEdit(long keyId) {
|
public void checkPassPhraseAndEdit(long masterKeyId) {
|
||||||
String passPhrase = PassphraseCacheService.getCachedPassphrase(this, keyId);
|
String passPhrase = PassphraseCacheService.getCachedPassphrase(this, masterKeyId);
|
||||||
if (passPhrase == null) {
|
if (passPhrase == null) {
|
||||||
showPassphraseDialog(keyId);
|
showPassphraseDialog(masterKeyId);
|
||||||
} else {
|
} else {
|
||||||
PgpMain.setEditPassPhrase(passPhrase);
|
PgpMain.setEditPassPhrase(passPhrase);
|
||||||
editKey(keyId);
|
editKey(masterKeyId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showPassphraseDialog(final long secretKeyId) {
|
private void showPassphraseDialog(final long masterKeyId) {
|
||||||
// Message is received after passphrase is cached
|
// Message is received after passphrase is cached
|
||||||
Handler returnHandler = new Handler() {
|
Handler returnHandler = new Handler() {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
|
if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
|
||||||
String passPhrase = PassphraseCacheService.getCachedPassphrase(
|
String passPhrase = PassphraseCacheService.getCachedPassphrase(
|
||||||
KeyListSecretActivity.this, secretKeyId);
|
KeyListSecretActivity.this, masterKeyId);
|
||||||
PgpMain.setEditPassPhrase(passPhrase);
|
PgpMain.setEditPassPhrase(passPhrase);
|
||||||
editKey(secretKeyId);
|
editKey(masterKeyId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -99,7 +99,7 @@ public class KeyListSecretActivity extends KeyListActivity {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PassphraseDialogFragment passphraseDialog = PassphraseDialogFragment.newInstance(
|
PassphraseDialogFragment passphraseDialog = PassphraseDialogFragment.newInstance(
|
||||||
KeyListSecretActivity.this, messenger, secretKeyId);
|
KeyListSecretActivity.this, messenger, masterKeyId);
|
||||||
|
|
||||||
passphraseDialog.show(getSupportFragmentManager(), "passphraseDialog");
|
passphraseDialog.show(getSupportFragmentManager(), "passphraseDialog");
|
||||||
} catch (PgpMain.PgpGeneralException e) {
|
} catch (PgpMain.PgpGeneralException e) {
|
||||||
|
@ -115,9 +115,9 @@ public class KeyListSecretActivity extends KeyListActivity {
|
||||||
startActivityForResult(intent, 0);
|
startActivityForResult(intent, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void editKey(long keyId) {
|
private void editKey(long masterKeyId) {
|
||||||
Intent intent = new Intent(EditKeyActivity.ACTION_EDIT_KEY);
|
Intent intent = new Intent(EditKeyActivity.ACTION_EDIT_KEY);
|
||||||
intent.putExtra(EditKeyActivity.EXTRA_KEY_ID, keyId);
|
intent.putExtra(EditKeyActivity.EXTRA_MASTER_KEY_ID, masterKeyId);
|
||||||
startActivityForResult(intent, 0);
|
startActivityForResult(intent, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue