mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22:16 -05:00
KeychainContract: use longs instead of String, other fixes
This commit is contained in:
parent
de6950377c
commit
80408460a0
@ -385,7 +385,7 @@ public class ContactHelper {
|
||||
int rawContactId, long masterKeyId) {
|
||||
ops.add(selectByRawContactAndItemType(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI),
|
||||
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);
|
||||
if (ids != null) {
|
||||
while (ids.moveToNext()) {
|
||||
|
@ -218,7 +218,7 @@ public class CachedPublicKeyRing extends KeyRing {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -172,8 +172,8 @@ public class KeychainContract {
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_PUBLIC).build();
|
||||
}
|
||||
|
||||
public static Uri buildPublicKeyRingUri(String masterKeyId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(masterKeyId).appendPath(PATH_PUBLIC).build();
|
||||
public static Uri buildPublicKeyRingUri(long masterKeyId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(Long.toString(masterKeyId)).appendPath(PATH_PUBLIC).build();
|
||||
}
|
||||
|
||||
public static Uri buildPublicKeyRingUri(Uri uri) {
|
||||
@ -184,8 +184,8 @@ public class KeychainContract {
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_SECRET).build();
|
||||
}
|
||||
|
||||
public static Uri buildSecretKeyRingUri(String masterKeyId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(masterKeyId).appendPath(PATH_SECRET).build();
|
||||
public static Uri buildSecretKeyRingUri(long masterKeyId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(Long.toString(masterKeyId)).appendPath(PATH_SECRET).build();
|
||||
}
|
||||
|
||||
public static Uri buildSecretKeyRingUri(Uri uri) {
|
||||
@ -210,8 +210,8 @@ public class KeychainContract {
|
||||
public static final String CONTENT_ITEM_TYPE
|
||||
= "vnd.android.cursor.item/vnd.org.sufficientlysecure.keychain.provider.keychain.keys";
|
||||
|
||||
public static Uri buildKeysUri(String masterKeyId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(masterKeyId).appendPath(PATH_KEYS).build();
|
||||
public static Uri buildKeysUri(long masterKeyId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(Long.toString(masterKeyId)).appendPath(PATH_KEYS).build();
|
||||
}
|
||||
|
||||
public static Uri buildKeysUri(Uri uri) {
|
||||
@ -237,8 +237,8 @@ public class KeychainContract {
|
||||
public static final String CONTENT_ITEM_TYPE
|
||||
= "vnd.android.cursor.item/vnd.org.sufficientlysecure.keychain.provider.user_ids";
|
||||
|
||||
public static Uri buildUserIdsUri(String masterKeyId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(masterKeyId).appendPath(PATH_USER_IDS).build();
|
||||
public static Uri buildUserIdsUri(long masterKeyId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(Long.toString(masterKeyId)).appendPath(PATH_USER_IDS).build();
|
||||
}
|
||||
|
||||
public static Uri buildUserIdsUri(Uri uri) {
|
||||
@ -304,12 +304,14 @@ public class KeychainContract {
|
||||
public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()
|
||||
.appendPath(BASE_KEY_RINGS).build();
|
||||
|
||||
public static Uri buildCertsUri(String masterKeyId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(masterKeyId).appendPath(PATH_CERTS).build();
|
||||
public static Uri buildCertsUri(long masterKeyId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(Long.toString(masterKeyId)).appendPath(PATH_CERTS).build();
|
||||
}
|
||||
|
||||
public static Uri buildCertsSpecificUri(String masterKeyId, String rank, String certifier) {
|
||||
return CONTENT_URI.buildUpon().appendPath(masterKeyId).appendPath(PATH_CERTS).appendPath(rank).appendPath(certifier).build();
|
||||
public static Uri buildCertsSpecificUri(long masterKeyId, long rank, long certifier) {
|
||||
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) {
|
||||
|
@ -299,7 +299,7 @@ public class ProviderHelper {
|
||||
return SaveKeyringResult.RESULT_ERROR;
|
||||
}
|
||||
|
||||
Uri uri = KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId));
|
||||
Uri uri = KeyRingData.buildPublicKeyRingUri(masterKeyId);
|
||||
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);
|
||||
mIndent += 1;
|
||||
{ // insert subkeys
|
||||
Uri uri = Keys.buildKeysUri(Long.toString(masterKeyId));
|
||||
Uri uri = Keys.buildKeysUri(masterKeyId);
|
||||
int rank = 0;
|
||||
for (CanonicalizedPublicKey key : keyRing.publicKeyIterator()) {
|
||||
long keyId = key.getKeyId();
|
||||
@ -498,7 +498,7 @@ public class ProviderHelper {
|
||||
try {
|
||||
// delete old version of this keyRing, which also deletes all keys and userIds on cascade
|
||||
int deleted = mContentResolver.delete(
|
||||
KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId)), null, null);
|
||||
KeyRingData.buildPublicKeyRingUri(masterKeyId), null, null);
|
||||
if (deleted > 0) {
|
||||
log(LogLevel.DEBUG, LogType.MSG_IP_DELETE_OLD_OK);
|
||||
result |= SaveKeyringResult.UPDATED;
|
||||
@ -567,7 +567,7 @@ public class ProviderHelper {
|
||||
values.put(KeyRingData.MASTER_KEY_ID, masterKeyId);
|
||||
values.put(KeyRingData.KEY_RING_DATA, keyRing.getEncoded());
|
||||
// insert new version of this keyRing
|
||||
Uri uri = KeyRingData.buildSecretKeyRingUri(Long.toString(masterKeyId));
|
||||
Uri uri = KeyRingData.buildSecretKeyRingUri(masterKeyId);
|
||||
if (mContentResolver.insert(uri, values) == null) {
|
||||
log(LogLevel.ERROR, LogType.MSG_IS_DB_EXCEPTION);
|
||||
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
|
||||
ContentValues values = new ContentValues();
|
||||
@ -836,7 +836,7 @@ public class ProviderHelper {
|
||||
values.put(Certs.VERIFIED, verified);
|
||||
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();
|
||||
}
|
||||
@ -853,7 +853,7 @@ public class ProviderHelper {
|
||||
values.put(UserIds.IS_REVOKED, item.isRevoked);
|
||||
values.put(UserIds.RANK, rank);
|
||||
|
||||
Uri uri = UserIds.buildUserIdsUri(Long.toString(masterKeyId));
|
||||
Uri uri = UserIds.buildUserIdsUri(masterKeyId);
|
||||
|
||||
return ContentProviderOperation.newInsert(uri).withValues(values).build();
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ import org.sufficientlysecure.keychain.helper.ActionBarHelper;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||
@ -215,8 +216,7 @@ public class EditKeyFragment extends LoaderFragment implements
|
||||
mUserIdsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
String userId = mUserIdsAdapter.getUserId(position);
|
||||
editUserId(userId);
|
||||
editUserId(position);
|
||||
}
|
||||
});
|
||||
|
||||
@ -230,8 +230,7 @@ public class EditKeyFragment extends LoaderFragment implements
|
||||
mSubkeysList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
long keyId = mSubkeysAdapter.getKeyId(position);
|
||||
editSubkey(keyId);
|
||||
editSubkey(position);
|
||||
}
|
||||
});
|
||||
|
||||
@ -320,7 +319,9 @@ public class EditKeyFragment extends LoaderFragment implements
|
||||
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() {
|
||||
@Override
|
||||
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() {
|
||||
@Override
|
||||
public void handleMessage(Message message) {
|
||||
switch (message.what) {
|
||||
case EditSubkeyDialogFragment.MESSAGE_CHANGE_EXPIRY:
|
||||
editSubkeyExpiry(keyId);
|
||||
editSubkeyExpiry(position);
|
||||
break;
|
||||
case EditSubkeyDialogFragment.MESSAGE_REVOKE:
|
||||
// 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() {
|
||||
@Override
|
||||
public void handleMessage(Message message) {
|
||||
switch (message.what) {
|
||||
case ChangeExpiryDialogFragment.MESSAGE_NEW_EXPIRY_DATE:
|
||||
// toggle
|
||||
// SaveKeyringParcel.SubkeyChange subkeyChange = new SaveKeyringParcel.SubkeyChange();
|
||||
|
||||
// mSaveKeyringParcel.mChangeSubKeys.add()
|
||||
// if (mSaveKeyringParcel.changePrimaryUserId != null
|
||||
// && mSaveKeyringParcel.changePrimaryUserId.equals(userId)) {
|
||||
// mSaveKeyringParcel.changePrimaryUserId = null;
|
||||
@ -419,7 +428,7 @@ public class EditKeyFragment extends LoaderFragment implements
|
||||
DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() {
|
||||
public void run() {
|
||||
ChangeExpiryDialogFragment dialogFragment =
|
||||
ChangeExpiryDialogFragment.newInstance(messenger, new Date(), new Date());
|
||||
ChangeExpiryDialogFragment.newInstance(messenger, creationDate, expiryDate);
|
||||
|
||||
dialogFragment.show(getActivity().getSupportFragmentManager(), "editSubkeyExpiryDialog");
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ public class ViewKeyCertsFragment extends LoaderFragment
|
||||
|
||||
Intent viewIntent = new Intent(getActivity(), ViewCertActivity.class);
|
||||
viewIntent.setData(Certs.buildCertsSpecificUri(
|
||||
Long.toString(masterKeyId), Long.toString(rank), Long.toString(certifierId)));
|
||||
masterKeyId, rank, certifierId));
|
||||
startActivity(viewIntent);
|
||||
}
|
||||
}
|
||||
|
@ -90,6 +90,16 @@ public class SubkeysAdapter extends CursorAdapter {
|
||||
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
|
||||
public Cursor swapCursor(Cursor newCursor) {
|
||||
hasAnySecret = false;
|
||||
|
@ -123,7 +123,7 @@ public class DeleteKeyDialogFragment extends DialogFragment {
|
||||
boolean success = false;
|
||||
for (long masterKeyId : masterKeyIds) {
|
||||
int count = activity.getContentResolver().delete(
|
||||
KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId)), null, null
|
||||
KeyRingData.buildPublicKeyRingUri(masterKeyId), null, null
|
||||
);
|
||||
success = count > 0;
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView {
|
||||
|
||||
private void initView() {
|
||||
swapCursor(null);
|
||||
setPrefix(getContext().getString(R.string.label_to) + ": ");
|
||||
setPrefix(getContext().getString(R.string.label_to));
|
||||
allowDuplicates(false);
|
||||
}
|
||||
|
||||
|
@ -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_summary">Writes \'OpenKeychain v2.7\' to OpenPGP signatures, ciphertext, and exported keys</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_decryption">Delete After Decryption</string>
|
||||
<string name="label_encryption_algorithm">Encryption Algorithm</string>
|
||||
|
Loading…
Reference in New Issue
Block a user