aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src/main/java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java6
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java21
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java25
3 files changed, 28 insertions, 24 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 ee28b5f36..177f07344 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java
@@ -109,6 +109,7 @@ public class KeychainContract {
public static final String PATH_FIND = "find";
public static final String PATH_BY_EMAIL = "email";
public static final String PATH_BY_SUBKEY = "subkey";
+ public static final String PATH_BY_USER_ID = "user_id";
public static final String PATH_PUBLIC = "public";
public static final String PATH_SECRET = "secret";
@@ -174,6 +175,11 @@ public class KeychainContract {
.appendPath(PATH_BY_EMAIL).appendPath(email).build();
}
+ public static Uri buildUnifiedKeyRingsFindByUserIdUri(String query) {
+ return CONTENT_URI.buildUpon().appendPath(PATH_FIND)
+ .appendPath(PATH_BY_USER_ID).appendPath(query).build();
+ }
+
public static Uri buildUnifiedKeyRingsFindBySubkeyUri(long subkey) {
return CONTENT_URI.buildUpon().appendPath(PATH_FIND)
.appendPath(PATH_BY_SUBKEY).appendPath(Long.toString(subkey)).build();
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 104343074..87b8a3b65 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java
@@ -28,6 +28,7 @@ import android.database.sqlite.SQLiteConstraintException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
+import android.support.annotation.NonNull;
import android.text.TextUtils;
import org.sufficientlysecure.keychain.Constants;
@@ -75,6 +76,7 @@ public class KeychainProvider extends ContentProvider {
private static final int KEY_RINGS_FIND_BY_EMAIL = 400;
private static final int KEY_RINGS_FIND_BY_SUBKEY = 401;
+ private static final int KEY_RINGS_FIND_BY_USER_ID = 402;
private static final int UPDATED_KEYS = 500;
private static final int UPDATED_KEYS_SPECIFIC = 501;
@@ -126,6 +128,9 @@ public class KeychainProvider extends ContentProvider {
matcher.addURI(authority, KeychainContract.BASE_KEY_RINGS + "/"
+ KeychainContract.PATH_FIND + "/" + KeychainContract.PATH_BY_SUBKEY + "/*",
KEY_RINGS_FIND_BY_SUBKEY);
+ matcher.addURI(authority, KeychainContract.BASE_KEY_RINGS + "/"
+ + KeychainContract.PATH_FIND + "/" + KeychainContract.PATH_BY_USER_ID + "/*",
+ KEY_RINGS_FIND_BY_USER_ID);
/**
* list key_ring specifics
@@ -226,7 +231,7 @@ public class KeychainProvider extends ContentProvider {
* {@inheritDoc}
*/
@Override
- public String getType(Uri uri) {
+ public String getType(@NonNull Uri uri) {
final int match = mUriMatcher.match(uri);
switch (match) {
case KEY_RING_PUBLIC:
@@ -270,7 +275,7 @@ public class KeychainProvider extends ContentProvider {
* {@inheritDoc}
*/
@Override
- public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
+ public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
Log.v(Constants.TAG, "query(uri=" + uri + ", proj=" + Arrays.toString(projection) + ")");
@@ -285,7 +290,8 @@ public class KeychainProvider extends ContentProvider {
case KEY_RING_UNIFIED:
case KEY_RINGS_UNIFIED:
case KEY_RINGS_FIND_BY_EMAIL:
- case KEY_RINGS_FIND_BY_SUBKEY: {
+ case KEY_RINGS_FIND_BY_SUBKEY:
+ case KEY_RINGS_FIND_BY_USER_ID: {
HashMap<String, String> projectionMap = new HashMap<>();
projectionMap.put(KeyRings._ID, Tables.KEYS + ".oid AS _id");
projectionMap.put(KeyRings.MASTER_KEY_ID, Tables.KEYS + "." + Keys.MASTER_KEY_ID);
@@ -432,7 +438,8 @@ public class KeychainProvider extends ContentProvider {
}
break;
}
- case KEY_RINGS_FIND_BY_EMAIL: {
+ case KEY_RINGS_FIND_BY_EMAIL:
+ case KEY_RINGS_FIND_BY_USER_ID: {
String chunks[] = uri.getLastPathSegment().split(" *, *");
boolean gotCondition = false;
String emailWhere = "";
@@ -446,7 +453,11 @@ public class KeychainProvider extends ContentProvider {
}
emailWhere += "tmp." + UserPackets.USER_ID + " LIKE ";
// match '*<email>', so it has to be at the *end* of the user id
- emailWhere += DatabaseUtils.sqlEscapeString("%<" + chunks[i] + ">");
+ if (match == KEY_RINGS_FIND_BY_EMAIL) {
+ emailWhere += DatabaseUtils.sqlEscapeString("%<" + chunks[i] + ">");
+ } else {
+ emailWhere += DatabaseUtils.sqlEscapeString("%" + chunks[i] + "%");
+ }
gotCondition = true;
}
if(gotCondition) {
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
index dd8107304..77139f5de 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
@@ -305,27 +305,16 @@ public class KeyListFragment extends LoaderFragment
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
// This is called when a new Loader needs to be created. This
// sample only has one Loader, so we don't care about the ID.
- Uri baseUri = KeyRings.buildUnifiedKeyRingsUri();
- String where = null;
- String whereArgs[] = null;
- if (mQuery != null) {
- String[] words = mQuery.trim().split("\\s+");
- whereArgs = new String[words.length];
- for (int i = 0; i < words.length; ++i) {
- if (where == null) {
- where = "";
- } else {
- where += " AND ";
- }
- where += KeyRings.USER_ID + " LIKE ?";
- whereArgs[i] = "%" + words[i] + "%";
- }
+ Uri uri;
+ if (!TextUtils.isEmpty(mQuery)) {
+ uri = KeyRings.buildUnifiedKeyRingsFindByUserIdUri(mQuery);
+ } else {
+ uri = KeyRings.buildUnifiedKeyRingsUri();
}
// Now create and return a CursorLoader that will take care of
// creating a Cursor for the data being displayed.
- return new CursorLoader(getActivity(), baseUri,
- KeyListAdapter.PROJECTION, where, whereArgs, ORDER);
+ return new CursorLoader(getActivity(), uri, KeyListAdapter.PROJECTION, null, null, ORDER);
}
@Override
@@ -351,8 +340,6 @@ public class KeyListFragment extends LoaderFragment
}
mAdapter.swapCursor(data);
- mStickyList.setAdapter(mAdapter);
-
// end action mode, if any
if (mActionMode != null) {
mActionMode.finish();