keylist: filter results by all user ids for search (fixes #1645)
This commit is contained in:
parent
6f74ba2f2d
commit
24ef87535f
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
if (match == KEY_RINGS_FIND_BY_EMAIL) {
|
||||
emailWhere += DatabaseUtils.sqlEscapeString("%<" + chunks[i] + ">");
|
||||
} else {
|
||||
emailWhere += DatabaseUtils.sqlEscapeString("%" + chunks[i] + "%");
|
||||
}
|
||||
gotCondition = true;
|
||||
}
|
||||
if(gotCondition) {
|
||||
|
|
|
@ -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 = "";
|
||||
Uri uri;
|
||||
if (!TextUtils.isEmpty(mQuery)) {
|
||||
uri = KeyRings.buildUnifiedKeyRingsFindByUserIdUri(mQuery);
|
||||
} else {
|
||||
where += " AND ";
|
||||
}
|
||||
where += KeyRings.USER_ID + " LIKE ?";
|
||||
whereArgs[i] = "%" + words[i] + "%";
|
||||
}
|
||||
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();
|
||||
|
|
Loading…
Reference in a new issue