diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure')
4 files changed, 33 insertions, 23 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java index 56168847f..dd59f8603 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java @@ -105,8 +105,9 @@ public class KeychainContract { public static class KeyRings implements BaseColumns, KeysColumns, UserIdsColumns { public static final String MASTER_KEY_ID = KeysColumns.MASTER_KEY_ID; - public static final String IS_REVOKED = KeysColumns.IS_REVOKED; + public static final String IS_REVOKED = KeychainDatabase.Tables.KEYS + "." + KeysColumns.IS_REVOKED; public static final String VERIFIED = CertsColumns.VERIFIED; + public static final String IS_EXPIRED = "is_expired"; public static final String HAS_ANY_SECRET = "has_any_secret"; public static final String HAS_ENCRYPT = "has_encrypt"; public static final String HAS_SIGN = "has_sign"; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java index b651069e9..2b686b8ff 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java @@ -271,6 +271,9 @@ public class KeychainProvider extends ContentProvider { "kE." + Keys.KEY_ID + " AS " + KeyRings.HAS_ENCRYPT); projectionMap.put(KeyRings.HAS_SIGN, "kS." + Keys.KEY_ID + " AS " + KeyRings.HAS_SIGN); + projectionMap.put(KeyRings.IS_EXPIRED, + "(" + Tables.KEYS + "." + Keys.EXPIRY + " < " + new Date().getTime() / 1000 + ") AS " + + KeyRings.IS_EXPIRED); qb.setProjectionMap(projectionMap); // Need this as list so we can search in it diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java index 3de617ca0..bc3b140c3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java @@ -145,24 +145,17 @@ public class EncryptAsymmetricFragment extends Fragment implements EncryptActivi KeyRings.MASTER_KEY_ID, KeyRings.KEY_ID, KeyRings.USER_ID, - KeyRings.EXPIRY, - KeyRings.IS_REVOKED, - // can certify info only related to master key - KeyRings.CAN_CERTIFY, - // has sign may be any subkey + KeyRings.IS_EXPIRED, KeyRings.HAS_SIGN, - KeyRings.HAS_ANY_SECRET, - KeyRings.HAS_SECRET + KeyRings.HAS_ANY_SECRET }; - String where = KeyRings.HAS_ANY_SECRET + " = 1"; + 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 // creating a Cursor for the data being displayed. return new CursorLoader(getActivity(), baseUri, projection, where, null, null); - /*return new CursorLoader(getActivity(), KeyRings.buildUnifiedKeyRingsUri(), - new String[]{KeyRings.USER_ID, KeyRings.KEY_ID, KeyRings.MASTER_KEY_ID, KeyRings.HAS_ANY_SECRET}, SIGN_KEY_SELECTION, - null, null);*/ } @Override diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java index 7e762fe77..20b9570bb 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java @@ -22,6 +22,7 @@ import android.content.Context; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.Rect; +import android.net.Uri; import android.os.Bundle; import android.support.v4.app.FragmentActivity; 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.exception.PgpGeneralException; 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 java.util.ArrayList; @@ -113,9 +114,23 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView { ((FragmentActivity) getContext()).getSupportLoaderManager().initLoader(0, null, new LoaderManager.LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { - return new CursorLoader(getContext(), KeychainContract.KeyRings.buildUnifiedKeyRingsUri(), - new String[]{KeychainContract.KeyRings.HAS_ENCRYPT, KeychainContract.KeyRings.KEY_ID, KeychainContract.KeyRings.USER_ID, KeychainContract.KeyRings.FINGERPRINT}, - null, null, null); + // These are the rows that we will retrieve. + Uri baseUri = KeyRings.buildUnifiedKeyRingsUri(); + + 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 @@ -148,10 +163,8 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView { ArrayList<EncryptionKey> keys = new ArrayList<EncryptionKey>(); while (cursor.moveToNext()) { try { - if (cursor.getInt(cursor.getColumnIndexOrThrow(KeychainContract.KeyRings.HAS_ENCRYPT)) != 0) { - EncryptionKey key = new EncryptionKey(cursor); - keys.add(key); - } + EncryptionKey key = new EncryptionKey(cursor); + keys.add(key); } catch (Exception e) { Log.w(Constants.TAG, e); return; @@ -174,10 +187,10 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView { } public EncryptionKey(Cursor cursor) { - this(cursor.getString(cursor.getColumnIndexOrThrow(KeychainContract.KeyRings.USER_ID)), - cursor.getLong(cursor.getColumnIndexOrThrow(KeychainContract.KeyRings.KEY_ID)), + this(cursor.getString(cursor.getColumnIndexOrThrow(KeyRings.USER_ID)), + cursor.getLong(cursor.getColumnIndexOrThrow(KeyRings.KEY_ID)), PgpKeyHelper.convertFingerprintToHex( - cursor.getBlob(cursor.getColumnIndexOrThrow(KeychainContract.KeyRings.FINGERPRINT)))); + cursor.getBlob(cursor.getColumnIndexOrThrow(KeyRings.FINGERPRINT)))); } |