Close cursor after getting data from DB
Fixes: 64487360 Test: manual Change-Id: I7d8a7550dca272a62b2c664cc893e4319e628c18
This commit is contained in:
@@ -17,6 +17,9 @@
|
|||||||
|
|
||||||
package com.android.settings.search;
|
package com.android.settings.search;
|
||||||
|
|
||||||
|
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns;
|
||||||
|
import static com.android.settings.search.IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
@@ -28,9 +31,6 @@ import com.android.settings.utils.AsyncLoader;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns;
|
|
||||||
import static com.android.settings.search.IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AsyncTask to retrieve Settings, First party app and any intent based results.
|
* AsyncTask to retrieve Settings, First party app and any intent based results.
|
||||||
*/
|
*/
|
||||||
@@ -191,11 +191,13 @@ public class DatabaseResultLoader extends AsyncLoader<Set<? extends SearchResult
|
|||||||
* @return A set of the matching results.
|
* @return A set of the matching results.
|
||||||
*/
|
*/
|
||||||
private Set<SearchResult> query(String whereClause, String[] selection, int baseRank) {
|
private Set<SearchResult> query(String whereClause, String[] selection, int baseRank) {
|
||||||
SQLiteDatabase database = IndexDatabaseHelper.getInstance(mContext).getReadableDatabase();
|
final SQLiteDatabase database =
|
||||||
final Cursor resultCursor = database.query(TABLE_PREFS_INDEX, SELECT_COLUMNS, whereClause,
|
IndexDatabaseHelper.getInstance(mContext).getReadableDatabase();
|
||||||
selection, null, null, null);
|
try (Cursor resultCursor = database.query(TABLE_PREFS_INDEX, SELECT_COLUMNS, whereClause,
|
||||||
|
selection, null, null, null)) {
|
||||||
return mConverter.convertCursor(mSiteMapManager, resultCursor, baseRank);
|
return mConverter.convertCursor(mSiteMapManager, resultCursor, baseRank);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the SQLite WHERE clause that matches all matchColumns for a single query.
|
* Builds the SQLite WHERE clause that matches all matchColumns for a single query.
|
||||||
|
@@ -34,7 +34,7 @@ import java.util.List;
|
|||||||
public class SavedQueryLoader extends AsyncLoader<List<? extends SearchResult>> {
|
public class SavedQueryLoader extends AsyncLoader<List<? extends SearchResult>> {
|
||||||
|
|
||||||
// Max number of proposed suggestions
|
// Max number of proposed suggestions
|
||||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
@VisibleForTesting
|
||||||
static final int MAX_PROPOSED_SUGGESTIONS = 5;
|
static final int MAX_PROPOSED_SUGGESTIONS = 5;
|
||||||
|
|
||||||
private final SQLiteDatabase mDatabase;
|
private final SQLiteDatabase mDatabase;
|
||||||
@@ -51,16 +51,18 @@ public class SavedQueryLoader extends AsyncLoader<List<? extends SearchResult>>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<? extends SearchResult> loadInBackground() {
|
public List<? extends SearchResult> loadInBackground() {
|
||||||
Cursor cursor = mDatabase.query(IndexDatabaseHelper.Tables.TABLE_SAVED_QUERIES /* table */,
|
try (final Cursor cursor = mDatabase.query(
|
||||||
|
IndexDatabaseHelper.Tables.TABLE_SAVED_QUERIES /* table */,
|
||||||
new String[]{SavedQueriesColumns.QUERY} /* columns */,
|
new String[]{SavedQueriesColumns.QUERY} /* columns */,
|
||||||
null /* selection */,
|
null /* selection */,
|
||||||
null /* selectionArgs */,
|
null /* selectionArgs */,
|
||||||
null /* groupBy */,
|
null /* groupBy */,
|
||||||
null /* having */,
|
null /* having */,
|
||||||
"rowId DESC" /* orderBy */,
|
"rowId DESC" /* orderBy */,
|
||||||
String.valueOf(MAX_PROPOSED_SUGGESTIONS) /* limit */);
|
String.valueOf(MAX_PROPOSED_SUGGESTIONS) /* limit */)) {
|
||||||
return convertCursorToResult(cursor);
|
return convertCursorToResult(cursor);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<SearchResult> convertCursorToResult(Cursor cursor) {
|
private List<SearchResult> convertCursorToResult(Cursor cursor) {
|
||||||
final List<SearchResult> results = new ArrayList<>();
|
final List<SearchResult> results = new ArrayList<>();
|
||||||
|
Reference in New Issue
Block a user