Only show relevant keys in encrypt, fix #756 #757

This commit is contained in:
mar-v-in 2014-08-12 13:56:30 +02:00
parent 80674021b5
commit 82a41a2f7c
2 changed files with 27 additions and 13 deletions

View File

@ -145,12 +145,13 @@ public class EncryptAsymmetricFragment extends Fragment implements EncryptActivi
KeyRings.MASTER_KEY_ID, KeyRings.MASTER_KEY_ID,
KeyRings.KEY_ID, KeyRings.KEY_ID,
KeyRings.USER_ID, KeyRings.USER_ID,
// has sign may be any subkey KeyRings.IS_EXPIRED,
KeyRings.HAS_SIGN, KeyRings.HAS_SIGN,
KeyRings.HAS_ANY_SECRET KeyRings.HAS_ANY_SECRET
}; };
String where = KeyRings.HAS_ANY_SECRET + " = 1 AND " + KeyRings.HAS_SIGN + " NOT NULL"; String where = KeyRings.HAS_ANY_SECRET + " = 1 AND " + KeyRings.HAS_SIGN + " NOT NULL AND "
+ KeyRings.IS_REVOKED + " = 0 AND " + KeyRings.IS_EXPIRED + " = 0";
// Now create and return a CursorLoader that will take care of // Now create and return a CursorLoader that will take care of
// creating a Cursor for the data being displayed. // creating a Cursor for the data being displayed.

View File

@ -22,6 +22,7 @@ import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Rect; import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager; import android.support.v4.app.LoaderManager;
@ -45,7 +46,7 @@ import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
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.CachedPublicKeyRing;
import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import java.util.ArrayList; import java.util.ArrayList;
@ -113,9 +114,23 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView {
((FragmentActivity) getContext()).getSupportLoaderManager().initLoader(0, null, new LoaderManager.LoaderCallbacks<Cursor>() { ((FragmentActivity) getContext()).getSupportLoaderManager().initLoader(0, null, new LoaderManager.LoaderCallbacks<Cursor>() {
@Override @Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) { public Loader<Cursor> onCreateLoader(int id, Bundle args) {
return new CursorLoader(getContext(), KeychainContract.KeyRings.buildUnifiedKeyRingsUri(), // These are the rows that we will retrieve.
new String[]{KeychainContract.KeyRings.HAS_ENCRYPT, KeychainContract.KeyRings.KEY_ID, KeychainContract.KeyRings.USER_ID, KeychainContract.KeyRings.FINGERPRINT}, Uri baseUri = KeyRings.buildUnifiedKeyRingsUri();
null, null, null);
String[] projection = new String[]{
KeyRings._ID,
KeyRings.MASTER_KEY_ID,
KeyRings.KEY_ID,
KeyRings.USER_ID,
KeyRings.FINGERPRINT,
KeyRings.IS_EXPIRED,
KeyRings.HAS_ENCRYPT
};
String where = KeyRings.HAS_ENCRYPT + " NOT NULL AND " + KeyRings.IS_EXPIRED + " = 0 AND "
+ KeyRings.IS_REVOKED + " = 0";
return new CursorLoader(getContext(), baseUri, projection, where, null, null);
} }
@Override @Override
@ -148,10 +163,8 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView {
ArrayList<EncryptionKey> keys = new ArrayList<EncryptionKey>(); ArrayList<EncryptionKey> keys = new ArrayList<EncryptionKey>();
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
try { try {
if (cursor.getInt(cursor.getColumnIndexOrThrow(KeychainContract.KeyRings.HAS_ENCRYPT)) != 0) { EncryptionKey key = new EncryptionKey(cursor);
EncryptionKey key = new EncryptionKey(cursor); keys.add(key);
keys.add(key);
}
} catch (Exception e) { } catch (Exception e) {
Log.w(Constants.TAG, e); Log.w(Constants.TAG, e);
return; return;
@ -174,10 +187,10 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView {
} }
public EncryptionKey(Cursor cursor) { public EncryptionKey(Cursor cursor) {
this(cursor.getString(cursor.getColumnIndexOrThrow(KeychainContract.KeyRings.USER_ID)), this(cursor.getString(cursor.getColumnIndexOrThrow(KeyRings.USER_ID)),
cursor.getLong(cursor.getColumnIndexOrThrow(KeychainContract.KeyRings.KEY_ID)), cursor.getLong(cursor.getColumnIndexOrThrow(KeyRings.KEY_ID)),
PgpKeyHelper.convertFingerprintToHex( PgpKeyHelper.convertFingerprintToHex(
cursor.getBlob(cursor.getColumnIndexOrThrow(KeychainContract.KeyRings.FINGERPRINT)))); cursor.getBlob(cursor.getColumnIndexOrThrow(KeyRings.FINGERPRINT))));
} }