KeychainContract: use longs instead of String, other fixes

This commit is contained in:
Dominik Schürmann 2014-08-05 00:23:04 +02:00
parent de6950377c
commit 80408460a0
10 changed files with 56 additions and 35 deletions

View File

@ -385,7 +385,7 @@ public class ContactHelper {
int rawContactId, long masterKeyId) { int rawContactId, long masterKeyId) {
ops.add(selectByRawContactAndItemType(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI), ops.add(selectByRawContactAndItemType(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI),
rawContactId, ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE).build()); rawContactId, ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE).build());
Cursor ids = resolver.query(KeychainContract.UserIds.buildUserIdsUri(Long.toString(masterKeyId)), Cursor ids = resolver.query(KeychainContract.UserIds.buildUserIdsUri(masterKeyId),
USER_IDS_PROJECTION, NON_REVOKED_SELECTION, null, null); USER_IDS_PROJECTION, NON_REVOKED_SELECTION, null, null);
if (ids != null) { if (ids != null) {
while (ids.moveToNext()) { while (ids.moveToNext()) {

View File

@ -218,7 +218,7 @@ public class CachedPublicKeyRing extends KeyRing {
} }
private Cursor getSubkeys() throws PgpGeneralException { private Cursor getSubkeys() throws PgpGeneralException {
Uri keysUri = KeychainContract.Keys.buildKeysUri(Long.toString(extractOrGetMasterKeyId())); Uri keysUri = KeychainContract.Keys.buildKeysUri(extractOrGetMasterKeyId());
return mProviderHelper.getContentResolver().query(keysUri, null, null, null, null); return mProviderHelper.getContentResolver().query(keysUri, null, null, null, null);
} }
} }

View File

@ -172,8 +172,8 @@ public class KeychainContract {
return CONTENT_URI.buildUpon().appendPath(PATH_PUBLIC).build(); return CONTENT_URI.buildUpon().appendPath(PATH_PUBLIC).build();
} }
public static Uri buildPublicKeyRingUri(String masterKeyId) { public static Uri buildPublicKeyRingUri(long masterKeyId) {
return CONTENT_URI.buildUpon().appendPath(masterKeyId).appendPath(PATH_PUBLIC).build(); return CONTENT_URI.buildUpon().appendPath(Long.toString(masterKeyId)).appendPath(PATH_PUBLIC).build();
} }
public static Uri buildPublicKeyRingUri(Uri uri) { public static Uri buildPublicKeyRingUri(Uri uri) {
@ -184,8 +184,8 @@ public class KeychainContract {
return CONTENT_URI.buildUpon().appendPath(PATH_SECRET).build(); return CONTENT_URI.buildUpon().appendPath(PATH_SECRET).build();
} }
public static Uri buildSecretKeyRingUri(String masterKeyId) { public static Uri buildSecretKeyRingUri(long masterKeyId) {
return CONTENT_URI.buildUpon().appendPath(masterKeyId).appendPath(PATH_SECRET).build(); return CONTENT_URI.buildUpon().appendPath(Long.toString(masterKeyId)).appendPath(PATH_SECRET).build();
} }
public static Uri buildSecretKeyRingUri(Uri uri) { public static Uri buildSecretKeyRingUri(Uri uri) {
@ -210,8 +210,8 @@ public class KeychainContract {
public static final String CONTENT_ITEM_TYPE public static final String CONTENT_ITEM_TYPE
= "vnd.android.cursor.item/vnd.org.sufficientlysecure.keychain.provider.keychain.keys"; = "vnd.android.cursor.item/vnd.org.sufficientlysecure.keychain.provider.keychain.keys";
public static Uri buildKeysUri(String masterKeyId) { public static Uri buildKeysUri(long masterKeyId) {
return CONTENT_URI.buildUpon().appendPath(masterKeyId).appendPath(PATH_KEYS).build(); return CONTENT_URI.buildUpon().appendPath(Long.toString(masterKeyId)).appendPath(PATH_KEYS).build();
} }
public static Uri buildKeysUri(Uri uri) { public static Uri buildKeysUri(Uri uri) {
@ -237,8 +237,8 @@ public class KeychainContract {
public static final String CONTENT_ITEM_TYPE public static final String CONTENT_ITEM_TYPE
= "vnd.android.cursor.item/vnd.org.sufficientlysecure.keychain.provider.user_ids"; = "vnd.android.cursor.item/vnd.org.sufficientlysecure.keychain.provider.user_ids";
public static Uri buildUserIdsUri(String masterKeyId) { public static Uri buildUserIdsUri(long masterKeyId) {
return CONTENT_URI.buildUpon().appendPath(masterKeyId).appendPath(PATH_USER_IDS).build(); return CONTENT_URI.buildUpon().appendPath(Long.toString(masterKeyId)).appendPath(PATH_USER_IDS).build();
} }
public static Uri buildUserIdsUri(Uri uri) { public static Uri buildUserIdsUri(Uri uri) {
@ -304,12 +304,14 @@ public class KeychainContract {
public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon() public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()
.appendPath(BASE_KEY_RINGS).build(); .appendPath(BASE_KEY_RINGS).build();
public static Uri buildCertsUri(String masterKeyId) { public static Uri buildCertsUri(long masterKeyId) {
return CONTENT_URI.buildUpon().appendPath(masterKeyId).appendPath(PATH_CERTS).build(); return CONTENT_URI.buildUpon().appendPath(Long.toString(masterKeyId)).appendPath(PATH_CERTS).build();
} }
public static Uri buildCertsSpecificUri(String masterKeyId, String rank, String certifier) { public static Uri buildCertsSpecificUri(long masterKeyId, long rank, long certifier) {
return CONTENT_URI.buildUpon().appendPath(masterKeyId).appendPath(PATH_CERTS).appendPath(rank).appendPath(certifier).build(); return CONTENT_URI.buildUpon().appendPath(Long.toString(masterKeyId))
.appendPath(PATH_CERTS).appendPath(Long.toString(rank))
.appendPath(Long.toString(certifier)).build();
} }
public static Uri buildCertsUri(Uri uri) { public static Uri buildCertsUri(Uri uri) {

View File

@ -299,7 +299,7 @@ public class ProviderHelper {
return SaveKeyringResult.RESULT_ERROR; return SaveKeyringResult.RESULT_ERROR;
} }
Uri uri = KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId)); Uri uri = KeyRingData.buildPublicKeyRingUri(masterKeyId);
operations.add(ContentProviderOperation.newInsert(uri).withValues(values).build()); operations.add(ContentProviderOperation.newInsert(uri).withValues(values).build());
} }
@ -307,7 +307,7 @@ public class ProviderHelper {
progress.setProgress(LogType.MSG_IP_INSERT_SUBKEYS.getMsgId(), 40, 100); progress.setProgress(LogType.MSG_IP_INSERT_SUBKEYS.getMsgId(), 40, 100);
mIndent += 1; mIndent += 1;
{ // insert subkeys { // insert subkeys
Uri uri = Keys.buildKeysUri(Long.toString(masterKeyId)); Uri uri = Keys.buildKeysUri(masterKeyId);
int rank = 0; int rank = 0;
for (CanonicalizedPublicKey key : keyRing.publicKeyIterator()) { for (CanonicalizedPublicKey key : keyRing.publicKeyIterator()) {
long keyId = key.getKeyId(); long keyId = key.getKeyId();
@ -498,7 +498,7 @@ public class ProviderHelper {
try { try {
// delete old version of this keyRing, which also deletes all keys and userIds on cascade // delete old version of this keyRing, which also deletes all keys and userIds on cascade
int deleted = mContentResolver.delete( int deleted = mContentResolver.delete(
KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId)), null, null); KeyRingData.buildPublicKeyRingUri(masterKeyId), null, null);
if (deleted > 0) { if (deleted > 0) {
log(LogLevel.DEBUG, LogType.MSG_IP_DELETE_OLD_OK); log(LogLevel.DEBUG, LogType.MSG_IP_DELETE_OLD_OK);
result |= SaveKeyringResult.UPDATED; result |= SaveKeyringResult.UPDATED;
@ -567,7 +567,7 @@ public class ProviderHelper {
values.put(KeyRingData.MASTER_KEY_ID, masterKeyId); values.put(KeyRingData.MASTER_KEY_ID, masterKeyId);
values.put(KeyRingData.KEY_RING_DATA, keyRing.getEncoded()); values.put(KeyRingData.KEY_RING_DATA, keyRing.getEncoded());
// insert new version of this keyRing // insert new version of this keyRing
Uri uri = KeyRingData.buildSecretKeyRingUri(Long.toString(masterKeyId)); Uri uri = KeyRingData.buildSecretKeyRingUri(masterKeyId);
if (mContentResolver.insert(uri, values) == null) { if (mContentResolver.insert(uri, values) == null) {
log(LogLevel.ERROR, LogType.MSG_IS_DB_EXCEPTION); log(LogLevel.ERROR, LogType.MSG_IS_DB_EXCEPTION);
return SaveKeyringResult.RESULT_ERROR; return SaveKeyringResult.RESULT_ERROR;
@ -579,7 +579,7 @@ public class ProviderHelper {
} }
{ {
Uri uri = Keys.buildKeysUri(Long.toString(masterKeyId)); Uri uri = Keys.buildKeysUri(masterKeyId);
// first, mark all keys as not available // first, mark all keys as not available
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
@ -836,7 +836,7 @@ public class ProviderHelper {
values.put(Certs.VERIFIED, verified); values.put(Certs.VERIFIED, verified);
values.put(Certs.DATA, cert.getEncoded()); values.put(Certs.DATA, cert.getEncoded());
Uri uri = Certs.buildCertsUri(Long.toString(masterKeyId)); Uri uri = Certs.buildCertsUri(masterKeyId);
return ContentProviderOperation.newInsert(uri).withValues(values).build(); return ContentProviderOperation.newInsert(uri).withValues(values).build();
} }
@ -853,7 +853,7 @@ public class ProviderHelper {
values.put(UserIds.IS_REVOKED, item.isRevoked); values.put(UserIds.IS_REVOKED, item.isRevoked);
values.put(UserIds.RANK, rank); values.put(UserIds.RANK, rank);
Uri uri = UserIds.buildUserIdsUri(Long.toString(masterKeyId)); Uri uri = UserIds.buildUserIdsUri(masterKeyId);
return ContentProviderOperation.newInsert(uri).withValues(values).build(); return ContentProviderOperation.newInsert(uri).withValues(values).build();
} }

View File

@ -45,6 +45,7 @@ import org.sufficientlysecure.keychain.helper.ActionBarHelper;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentService;
@ -215,8 +216,7 @@ public class EditKeyFragment extends LoaderFragment implements
mUserIdsList.setOnItemClickListener(new AdapterView.OnItemClickListener() { mUserIdsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String userId = mUserIdsAdapter.getUserId(position); editUserId(position);
editUserId(userId);
} }
}); });
@ -230,8 +230,7 @@ public class EditKeyFragment extends LoaderFragment implements
mSubkeysList.setOnItemClickListener(new AdapterView.OnItemClickListener() { mSubkeysList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
long keyId = mSubkeysAdapter.getKeyId(position); editSubkey(position);
editSubkey(keyId);
} }
}); });
@ -320,7 +319,9 @@ public class EditKeyFragment extends LoaderFragment implements
setPassphraseDialog.show(getActivity().getSupportFragmentManager(), "setPassphraseDialog"); setPassphraseDialog.show(getActivity().getSupportFragmentManager(), "setPassphraseDialog");
} }
private void editUserId(final String userId) { private void editUserId(final int position) {
final String userId = mUserIdsAdapter.getUserId(position);
Handler returnHandler = new Handler() { Handler returnHandler = new Handler() {
@Override @Override
public void handleMessage(Message message) { public void handleMessage(Message message) {
@ -360,13 +361,15 @@ public class EditKeyFragment extends LoaderFragment implements
}); });
} }
private void editSubkey(final long keyId) { private void editSubkey(final int position) {
final long keyId = mSubkeysAdapter.getKeyId(position);
Handler returnHandler = new Handler() { Handler returnHandler = new Handler() {
@Override @Override
public void handleMessage(Message message) { public void handleMessage(Message message) {
switch (message.what) { switch (message.what) {
case EditSubkeyDialogFragment.MESSAGE_CHANGE_EXPIRY: case EditSubkeyDialogFragment.MESSAGE_CHANGE_EXPIRY:
editSubkeyExpiry(keyId); editSubkeyExpiry(position);
break; break;
case EditSubkeyDialogFragment.MESSAGE_REVOKE: case EditSubkeyDialogFragment.MESSAGE_REVOKE:
// toggle // toggle
@ -394,13 +397,19 @@ public class EditKeyFragment extends LoaderFragment implements
}); });
} }
private void editSubkeyExpiry(final long keyId) { private void editSubkeyExpiry(final int position) {
final long keyId = mSubkeysAdapter.getKeyId(position);
final Date creationDate = new Date(mSubkeysAdapter.getCreationDate(position));
final Date expiryDate = new Date(mSubkeysAdapter.getExpiryDate(position));
Handler returnHandler = new Handler() { Handler returnHandler = new Handler() {
@Override @Override
public void handleMessage(Message message) { public void handleMessage(Message message) {
switch (message.what) { switch (message.what) {
case ChangeExpiryDialogFragment.MESSAGE_NEW_EXPIRY_DATE: case ChangeExpiryDialogFragment.MESSAGE_NEW_EXPIRY_DATE:
// toggle // SaveKeyringParcel.SubkeyChange subkeyChange = new SaveKeyringParcel.SubkeyChange();
// mSaveKeyringParcel.mChangeSubKeys.add()
// if (mSaveKeyringParcel.changePrimaryUserId != null // if (mSaveKeyringParcel.changePrimaryUserId != null
// && mSaveKeyringParcel.changePrimaryUserId.equals(userId)) { // && mSaveKeyringParcel.changePrimaryUserId.equals(userId)) {
// mSaveKeyringParcel.changePrimaryUserId = null; // mSaveKeyringParcel.changePrimaryUserId = null;
@ -419,7 +428,7 @@ public class EditKeyFragment extends LoaderFragment implements
DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() { DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() {
public void run() { public void run() {
ChangeExpiryDialogFragment dialogFragment = ChangeExpiryDialogFragment dialogFragment =
ChangeExpiryDialogFragment.newInstance(messenger, new Date(), new Date()); ChangeExpiryDialogFragment.newInstance(messenger, creationDate, expiryDate);
dialogFragment.show(getActivity().getSupportFragmentManager(), "editSubkeyExpiryDialog"); dialogFragment.show(getActivity().getSupportFragmentManager(), "editSubkeyExpiryDialog");
} }

View File

@ -150,7 +150,7 @@ public class ViewKeyCertsFragment extends LoaderFragment
Intent viewIntent = new Intent(getActivity(), ViewCertActivity.class); Intent viewIntent = new Intent(getActivity(), ViewCertActivity.class);
viewIntent.setData(Certs.buildCertsSpecificUri( viewIntent.setData(Certs.buildCertsSpecificUri(
Long.toString(masterKeyId), Long.toString(rank), Long.toString(certifierId))); masterKeyId, rank, certifierId));
startActivity(viewIntent); startActivity(viewIntent);
} }
} }

View File

@ -90,6 +90,16 @@ public class SubkeysAdapter extends CursorAdapter {
return mCursor.getLong(INDEX_KEY_ID); return mCursor.getLong(INDEX_KEY_ID);
} }
public long getCreationDate(int position) {
mCursor.moveToPosition(position);
return mCursor.getLong(INDEX_CREATION);
}
public long getExpiryDate(int position) {
mCursor.moveToPosition(position);
return mCursor.getLong(INDEX_EXPIRY);
}
@Override @Override
public Cursor swapCursor(Cursor newCursor) { public Cursor swapCursor(Cursor newCursor) {
hasAnySecret = false; hasAnySecret = false;

View File

@ -123,7 +123,7 @@ public class DeleteKeyDialogFragment extends DialogFragment {
boolean success = false; boolean success = false;
for (long masterKeyId : masterKeyIds) { for (long masterKeyId : masterKeyIds) {
int count = activity.getContentResolver().delete( int count = activity.getContentResolver().delete(
KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId)), null, null KeyRingData.buildPublicKeyRingUri(masterKeyId), null, null
); );
success = count > 0; success = count > 0;
} }

View File

@ -69,7 +69,7 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView {
private void initView() { private void initView() {
swapCursor(null); swapCursor(null);
setPrefix(getContext().getString(R.string.label_to) + ": "); setPrefix(getContext().getString(R.string.label_to));
allowDuplicates(false); allowDuplicates(false);
} }

View File

@ -92,7 +92,7 @@
<string name="label_conceal_pgp_application">Let others know that you\'re using OpenKeychain</string> <string name="label_conceal_pgp_application">Let others know that you\'re using OpenKeychain</string>
<string name="label_conceal_pgp_application_summary">Writes \'OpenKeychain v2.7\' to OpenPGP signatures, ciphertext, and exported keys</string> <string name="label_conceal_pgp_application_summary">Writes \'OpenKeychain v2.7\' to OpenPGP signatures, ciphertext, and exported keys</string>
<string name="label_asymmetric_from">From:</string> <string name="label_asymmetric_from">From:</string>
<string name="label_to">To</string> <string name="label_to">To:</string>
<string name="label_delete_after_encryption">Files: Delete After Encryption</string> <string name="label_delete_after_encryption">Files: Delete After Encryption</string>
<string name="label_delete_after_decryption">Delete After Decryption</string> <string name="label_delete_after_decryption">Delete After Decryption</string>
<string name="label_encryption_algorithm">Encryption Algorithm</string> <string name="label_encryption_algorithm">Encryption Algorithm</string>