close database when cursor is closed for external provider

This commit is contained in:
Vincent Breitmoser
2017-08-29 19:38:25 +02:00
parent b450909300
commit 6e8a768011
2 changed files with 44 additions and 5 deletions

View File

@@ -53,6 +53,7 @@ import org.sufficientlysecure.keychain.provider.KeychainExternalContract;
import org.sufficientlysecure.keychain.provider.KeychainExternalContract.AutocryptStatus;
import org.sufficientlysecure.keychain.provider.KeychainExternalContract.EmailStatus;
import org.sufficientlysecure.keychain.provider.SimpleContentResolverInterface;
import org.sufficientlysecure.keychain.util.CloseDatabaseCursorFactory;
import org.sufficientlysecure.keychain.util.Log;
public class KeychainExternalProvider extends ContentProvider implements SimpleContentResolverInterface {
@@ -107,10 +108,6 @@ public class KeychainExternalProvider extends ContentProvider implements SimpleC
return true;
}
public KeychainDatabase getDb() {
return new KeychainDatabase(getContext());
}
/**
* {@inheritDoc}
*/
@@ -146,7 +143,7 @@ public class KeychainExternalProvider extends ContentProvider implements SimpleC
String groupBy = null;
SQLiteDatabase db = getDb().getReadableDatabase();
SQLiteDatabase db = new KeychainDatabase(getContext()).getReadableDatabase();
String callingPackageName = mApiPermissionHelper.getCurrentCallingPackage();
@@ -343,6 +340,7 @@ public class KeychainExternalProvider extends ContentProvider implements SimpleC
}
Cursor cursor = qb.query(db, projection, selection, null, groupBy, null, orderBy);
qb.setCursorFactory(new CloseDatabaseCursorFactory());
if (cursor != null) {
// Tell the cursor what uri to watch, so it knows when its source data changes
cursor.setNotificationUri(getContext().getContentResolver(), uri);