@@ -205,9 +205,18 @@ public class ProviderHelper {
|
||||
PGPPublicKey masterKey = keyRing.getPublicKey();
|
||||
long masterKeyId = masterKey.getKeyID();
|
||||
|
||||
// delete old version of this keyRing, which also deletes all keys and userIds on cascade
|
||||
Uri deleteUri = KeyRings.buildPublicKeyRingsByMasterKeyIdUri(Long.toString(masterKeyId));
|
||||
|
||||
// get current _ID of key
|
||||
long currentRowId = -1;
|
||||
Cursor oldQuery = context.getContentResolver().query(deleteUri, new String[]{KeyRings._ID}, null, null, null);
|
||||
if (oldQuery != null && oldQuery.moveToFirst()) {
|
||||
currentRowId = oldQuery.getLong(0);
|
||||
} else {
|
||||
Log.e(Constants.TAG, "Key could not be found! Something wrong is happening!");
|
||||
}
|
||||
|
||||
// delete old version of this keyRing, which also deletes all keys and userIds on cascade
|
||||
try {
|
||||
context.getContentResolver().delete(deleteUri, null, null);
|
||||
} catch (UnsupportedOperationException e) {
|
||||
@@ -215,6 +224,11 @@ public class ProviderHelper {
|
||||
}
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
// use exactly the same _ID again to replace key in-place.
|
||||
// NOTE: If we would not use the same _ID again, getting back to the ViewKeyActivity would result in Nullpointer,
|
||||
// because the currently loaded key would be gone from the database
|
||||
if (currentRowId != -1)
|
||||
values.put(KeyRings._ID, currentRowId);
|
||||
values.put(KeyRings.MASTER_KEY_ID, masterKeyId);
|
||||
values.put(KeyRings.KEY_RING_DATA, keyRing.getEncoded());
|
||||
|
||||
@@ -261,9 +275,18 @@ public class ProviderHelper {
|
||||
PGPSecretKey masterKey = keyRing.getSecretKey();
|
||||
long masterKeyId = masterKey.getKeyID();
|
||||
|
||||
// delete old version of this keyRing, which also deletes all keys and userIds on cascade
|
||||
Uri deleteUri = KeyRings.buildSecretKeyRingsByMasterKeyIdUri(Long.toString(masterKeyId));
|
||||
|
||||
// get current _ID of key
|
||||
long currentRowId = -1;
|
||||
Cursor oldQuery = context.getContentResolver().query(deleteUri, new String[]{KeyRings._ID}, null, null, null);
|
||||
if (oldQuery != null && oldQuery.moveToFirst()) {
|
||||
currentRowId = oldQuery.getLong(0);
|
||||
} else {
|
||||
Log.e(Constants.TAG, "Key could not be found! Something wrong is happening!");
|
||||
}
|
||||
|
||||
// delete old version of this keyRing, which also deletes all keys and userIds on cascade
|
||||
try {
|
||||
context.getContentResolver().delete(deleteUri, null, null);
|
||||
} catch (UnsupportedOperationException e) {
|
||||
@@ -271,6 +294,11 @@ public class ProviderHelper {
|
||||
}
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
// use exactly the same _ID again to replace key in-place.
|
||||
// NOTE: If we would not use the same _ID again, getting back to the ViewKeyActivity would result in Nullpointer,
|
||||
// because the currently loaded key would be gone from the database
|
||||
if (currentRowId != -1)
|
||||
values.put(KeyRings._ID, currentRowId);
|
||||
values.put(KeyRings.MASTER_KEY_ID, masterKeyId);
|
||||
values.put(KeyRings.KEY_RING_DATA, keyRing.getEncoded());
|
||||
|
||||
|
||||
@@ -236,6 +236,7 @@ public class SignKeyActivity extends SherlockFragmentActivity implements
|
||||
*/
|
||||
uploadKey();
|
||||
} else {
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -278,10 +279,10 @@ public class SignKeyActivity extends SherlockFragmentActivity implements
|
||||
super.handleMessage(message);
|
||||
|
||||
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
|
||||
|
||||
Toast.makeText(SignKeyActivity.this, R.string.key_send_success,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.spongycastle.openpgp.PGPPublicKey;
|
||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
||||
@@ -111,16 +112,7 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements
|
||||
mUserIds = (ListView) findViewById(R.id.user_ids);
|
||||
mKeys = (ListView) findViewById(R.id.keys);
|
||||
|
||||
Intent intent = getIntent();
|
||||
mDataUri = intent.getData();
|
||||
if (mDataUri == null) {
|
||||
Log.e(Constants.TAG, "Intent data missing. Should be Uri of key!");
|
||||
finish();
|
||||
return;
|
||||
} else {
|
||||
Log.d(Constants.TAG, "uri: " + mDataUri);
|
||||
loadData(mDataUri);
|
||||
}
|
||||
loadData(getIntent());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -188,7 +180,21 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void loadData(Uri dataUri) {
|
||||
private void loadData(Intent intent) {
|
||||
if (intent.getData().equals(mDataUri)) {
|
||||
Log.d(Constants.TAG, "Same URI, no need to load the data again!");
|
||||
return;
|
||||
}
|
||||
|
||||
mDataUri = intent.getData();
|
||||
if (mDataUri == null) {
|
||||
Log.e(Constants.TAG, "Intent data missing. Should be Uri of key!");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
Log.i(Constants.TAG, "mDataUri: " + mDataUri.toString());
|
||||
|
||||
mActionEncrypt.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
@@ -340,7 +346,6 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements
|
||||
|
||||
// TODO: Can this be done better? fingerprint in db?
|
||||
String fingerprint = PgpKeyHelper.getFingerPrint(this, keyId);
|
||||
|
||||
fingerprint = fingerprint.replace(" ", "\n");
|
||||
mFingerprint.setText(fingerprint);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user