mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 21:55:10 +00:00
Make sure the cursor is always closed
This commit is contained in:
@@ -83,7 +83,7 @@ class AppDatabase {
|
||||
void setEnabled(String packageName, boolean isEnabled) {
|
||||
String[] columns = new String[]{KEY_IS_ENABLED};
|
||||
Cursor res = ourDatabase.query(DATABASE_TABLE, columns, KEY_PACKAGE_NAME + " =? ", new String[]{packageName}, null, null, null);
|
||||
|
||||
try {
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(KEY_IS_ENABLED, isEnabled ? "true" : "false");
|
||||
if (res.getCount() > 0) {
|
||||
@@ -92,8 +92,10 @@ class AppDatabase {
|
||||
cv.put(KEY_PACKAGE_NAME, packageName);
|
||||
ourDatabase.insert(DATABASE_TABLE, null, cv);
|
||||
}
|
||||
} finally {
|
||||
res.close();
|
||||
}
|
||||
}
|
||||
|
||||
void setAllEnabled(boolean enabled) {
|
||||
ourDatabase.execSQL("UPDATE " + DATABASE_TABLE + " SET " + KEY_IS_ENABLED + "='" + enabled + "'");
|
||||
@@ -102,6 +104,7 @@ class AppDatabase {
|
||||
boolean isEnabled(String packageName) {
|
||||
String[] columns = new String[]{KEY_IS_ENABLED};
|
||||
Cursor res = ourDatabase.query(DATABASE_TABLE, columns, KEY_PACKAGE_NAME + " =? ", new String[]{packageName}, null, null, null);
|
||||
try {
|
||||
boolean result;
|
||||
if (res.getCount() > 0) {
|
||||
res.moveToFirst();
|
||||
@@ -109,8 +112,10 @@ class AppDatabase {
|
||||
} else {
|
||||
result = getDefaultStatus(packageName);
|
||||
}
|
||||
res.close();
|
||||
return result;
|
||||
} finally {
|
||||
res.close();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean getDefaultStatus(String packageName) {
|
||||
|
Reference in New Issue
Block a user