Close cursor after getting data from DB

Fixes: 64487360
Test: manual

Change-Id: I7d8a7550dca272a62b2c664cc893e4319e628c18
This commit is contained in:
Fan Zhang
2017-08-07 15:11:00 -07:00
parent f1398725a8
commit 623faaa00e
2 changed files with 15 additions and 11 deletions

View File

@@ -17,6 +17,9 @@
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.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
@@ -28,9 +31,6 @@ import com.android.settings.utils.AsyncLoader;
import java.util.HashSet;
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.
*/
@@ -191,10 +191,12 @@ public class DatabaseResultLoader extends AsyncLoader<Set<? extends SearchResult
* @return A set of the matching results.
*/
private Set<SearchResult> query(String whereClause, String[] selection, int baseRank) {
SQLiteDatabase database = IndexDatabaseHelper.getInstance(mContext).getReadableDatabase();
final Cursor resultCursor = database.query(TABLE_PREFS_INDEX, SELECT_COLUMNS, whereClause,
selection, null, null, null);
return mConverter.convertCursor(mSiteMapManager, resultCursor, baseRank);
final SQLiteDatabase database =
IndexDatabaseHelper.getInstance(mContext).getReadableDatabase();
try (Cursor resultCursor = database.query(TABLE_PREFS_INDEX, SELECT_COLUMNS, whereClause,
selection, null, null, null)) {
return mConverter.convertCursor(mSiteMapManager, resultCursor, baseRank);
}
}
/**