mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-11 00:28:35 +00:00
SES-1251 - App crash on non alphanumeric first char search (#1393)
* Investigation in progress * Working fix push before cleanup * Fixes #1346 * Removed unused logging imports * Put back some whitespace * Minor cleanup
This commit is contained in:
parent
d3c8635748
commit
7a7ea8909d
@ -1,6 +1,5 @@
|
|||||||
package org.thoughtcrime.securesms.components;
|
package org.thoughtcrime.securesms.components;
|
||||||
|
|
||||||
|
|
||||||
import android.animation.Animator;
|
import android.animation.Animator;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@ -68,9 +67,7 @@ public class SearchToolbar extends LinearLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextChange(String newText) {
|
public boolean onQueryTextChange(String newText) { return onQueryTextSubmit(newText); }
|
||||||
return onQueryTextSubmit(newText);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
|
searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
|
||||||
|
@ -10,6 +10,7 @@ import com.annimon.stream.Stream;
|
|||||||
import net.zetetic.database.sqlcipher.SQLiteDatabase;
|
import net.zetetic.database.sqlcipher.SQLiteDatabase;
|
||||||
|
|
||||||
import org.session.libsession.utilities.Util;
|
import org.session.libsession.utilities.Util;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -115,9 +116,7 @@ public class SearchDatabase extends Database {
|
|||||||
public Cursor queryMessages(@NonNull String query) {
|
public Cursor queryMessages(@NonNull String query) {
|
||||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||||
String prefixQuery = adjustQuery(query);
|
String prefixQuery = adjustQuery(query);
|
||||||
|
|
||||||
int queryLimit = Math.min(query.length()*50,500);
|
int queryLimit = Math.min(query.length()*50,500);
|
||||||
|
|
||||||
Cursor cursor = db.rawQuery(MESSAGES_QUERY, new String[] { prefixQuery, prefixQuery, String.valueOf(queryLimit) });
|
Cursor cursor = db.rawQuery(MESSAGES_QUERY, new String[] { prefixQuery, prefixQuery, String.valueOf(queryLimit) });
|
||||||
setNotifyConversationListListeners(cursor);
|
setNotifyConversationListListeners(cursor);
|
||||||
return cursor;
|
return cursor;
|
||||||
|
@ -293,7 +293,6 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
val newData = contactResults + messageResults
|
val newData = contactResults + messageResults
|
||||||
|
|
||||||
globalSearchAdapter.setNewData(result.query, newData)
|
globalSearchAdapter.setNewData(result.query, newData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,16 @@ public class SearchRepository {
|
|||||||
Stopwatch timer = new Stopwatch("FtsQuery");
|
Stopwatch timer = new Stopwatch("FtsQuery");
|
||||||
|
|
||||||
String cleanQuery = sanitizeQuery(query);
|
String cleanQuery = sanitizeQuery(query);
|
||||||
|
|
||||||
|
// If the search is for a single character and it was stripped by `sanitizeQuery` then abort
|
||||||
|
// the search for an empty string to avoid SQLite error.
|
||||||
|
if (cleanQuery.length() == 0)
|
||||||
|
{
|
||||||
|
Log.d(TAG, "Aborting empty search query.");
|
||||||
|
timer.stop(TAG);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
timer.split("clean");
|
timer.split("clean");
|
||||||
|
|
||||||
Pair<CursorList<Contact>, List<String>> contacts = queryContacts(cleanQuery);
|
Pair<CursorList<Contact>, List<String>> contacts = queryContacts(cleanQuery);
|
||||||
@ -119,10 +129,11 @@ public class SearchRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
executor.execute(() -> {
|
executor.execute(() -> {
|
||||||
long startTime = System.currentTimeMillis();
|
// If the sanitized search query is empty then abort the search to prevent SQLite errors.
|
||||||
CursorList<MessageResult> messages = queryMessages(sanitizeQuery(query), threadId);
|
String cleanQuery = sanitizeQuery(query).trim();
|
||||||
Log.d(TAG, "[ConversationQuery] " + (System.currentTimeMillis() - startTime) + " ms");
|
if (cleanQuery.isEmpty()) { return; }
|
||||||
|
|
||||||
|
CursorList<MessageResult> messages = queryMessages(cleanQuery, threadId);
|
||||||
callback.onResult(messages);
|
callback.onResult(messages);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -215,7 +226,7 @@ public class SearchRepository {
|
|||||||
out.append(' ');
|
out.append(' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user