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_FIND = "find";
|
||||||
public static final String PATH_BY_EMAIL = "email";
|
public static final String PATH_BY_EMAIL = "email";
|
||||||
public static final String PATH_BY_SUBKEY = "subkey";
|
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_PUBLIC = "public";
|
||||||
public static final String PATH_SECRET = "secret";
|
public static final String PATH_SECRET = "secret";
|
||||||
|
@ -174,6 +175,11 @@ public class KeychainContract {
|
||||||
.appendPath(PATH_BY_EMAIL).appendPath(email).build();
|
.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) {
|
public static Uri buildUnifiedKeyRingsFindBySubkeyUri(long subkey) {
|
||||||
return CONTENT_URI.buildUpon().appendPath(PATH_FIND)
|
return CONTENT_URI.buildUpon().appendPath(PATH_FIND)
|
||||||
.appendPath(PATH_BY_SUBKEY).appendPath(Long.toString(subkey)).build();
|
.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.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteQueryBuilder;
|
import android.database.sqlite.SQLiteQueryBuilder;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
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_EMAIL = 400;
|
||||||
private static final int KEY_RINGS_FIND_BY_SUBKEY = 401;
|
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 = 500;
|
||||||
private static final int UPDATED_KEYS_SPECIFIC = 501;
|
private static final int UPDATED_KEYS_SPECIFIC = 501;
|
||||||
|
@ -126,6 +128,9 @@ public class KeychainProvider extends ContentProvider {
|
||||||
matcher.addURI(authority, KeychainContract.BASE_KEY_RINGS + "/"
|
matcher.addURI(authority, KeychainContract.BASE_KEY_RINGS + "/"
|
||||||
+ KeychainContract.PATH_FIND + "/" + KeychainContract.PATH_BY_SUBKEY + "/*",
|
+ KeychainContract.PATH_FIND + "/" + KeychainContract.PATH_BY_SUBKEY + "/*",
|
||||||
KEY_RINGS_FIND_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
|
* list key_ring specifics
|
||||||
|
@ -226,7 +231,7 @@ public class KeychainProvider extends ContentProvider {
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getType(Uri uri) {
|
public String getType(@NonNull Uri uri) {
|
||||||
final int match = mUriMatcher.match(uri);
|
final int match = mUriMatcher.match(uri);
|
||||||
switch (match) {
|
switch (match) {
|
||||||
case KEY_RING_PUBLIC:
|
case KEY_RING_PUBLIC:
|
||||||
|
@ -270,7 +275,7 @@ public class KeychainProvider extends ContentProvider {
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@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) {
|
String sortOrder) {
|
||||||
Log.v(Constants.TAG, "query(uri=" + uri + ", proj=" + Arrays.toString(projection) + ")");
|
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_RING_UNIFIED:
|
||||||
case KEY_RINGS_UNIFIED:
|
case KEY_RINGS_UNIFIED:
|
||||||
case KEY_RINGS_FIND_BY_EMAIL:
|
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<>();
|
HashMap<String, String> projectionMap = new HashMap<>();
|
||||||
projectionMap.put(KeyRings._ID, Tables.KEYS + ".oid AS _id");
|
projectionMap.put(KeyRings._ID, Tables.KEYS + ".oid AS _id");
|
||||||
projectionMap.put(KeyRings.MASTER_KEY_ID, Tables.KEYS + "." + Keys.MASTER_KEY_ID);
|
projectionMap.put(KeyRings.MASTER_KEY_ID, Tables.KEYS + "." + Keys.MASTER_KEY_ID);
|
||||||
|
@ -432,7 +438,8 @@ public class KeychainProvider extends ContentProvider {
|
||||||
}
|
}
|
||||||
break;
|
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(" *, *");
|
String chunks[] = uri.getLastPathSegment().split(" *, *");
|
||||||
boolean gotCondition = false;
|
boolean gotCondition = false;
|
||||||
String emailWhere = "";
|
String emailWhere = "";
|
||||||
|
@ -446,7 +453,11 @@ public class KeychainProvider extends ContentProvider {
|
||||||
}
|
}
|
||||||
emailWhere += "tmp." + UserPackets.USER_ID + " LIKE ";
|
emailWhere += "tmp." + UserPackets.USER_ID + " LIKE ";
|
||||||
// match '*<email>', so it has to be at the *end* of the user id
|
// 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;
|
gotCondition = true;
|
||||||
}
|
}
|
||||||
if(gotCondition) {
|
if(gotCondition) {
|
||||||
|
|
|
@ -305,27 +305,16 @@ public class KeyListFragment extends LoaderFragment
|
||||||
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
||||||
// This is called when a new Loader needs to be created. This
|
// 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.
|
// sample only has one Loader, so we don't care about the ID.
|
||||||
Uri baseUri = KeyRings.buildUnifiedKeyRingsUri();
|
Uri uri;
|
||||||
String where = null;
|
if (!TextUtils.isEmpty(mQuery)) {
|
||||||
String whereArgs[] = null;
|
uri = KeyRings.buildUnifiedKeyRingsFindByUserIdUri(mQuery);
|
||||||
if (mQuery != null) {
|
} else {
|
||||||
String[] words = mQuery.trim().split("\\s+");
|
uri = KeyRings.buildUnifiedKeyRingsUri();
|
||||||
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] + "%";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
return new CursorLoader(getActivity(), baseUri,
|
return new CursorLoader(getActivity(), uri, KeyListAdapter.PROJECTION, null, null, ORDER);
|
||||||
KeyListAdapter.PROJECTION, where, whereArgs, ORDER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -351,8 +340,6 @@ public class KeyListFragment extends LoaderFragment
|
||||||
}
|
}
|
||||||
mAdapter.swapCursor(data);
|
mAdapter.swapCursor(data);
|
||||||
|
|
||||||
mStickyList.setAdapter(mAdapter);
|
|
||||||
|
|
||||||
// end action mode, if any
|
// end action mode, if any
|
||||||
if (mActionMode != null) {
|
if (mActionMode != null) {
|
||||||
mActionMode.finish();
|
mActionMode.finish();
|
||||||
|
|
Loading…
Reference in a new issue