close database when cursor is closed for external provider
This commit is contained in:
parent
b450909300
commit
6e8a768011
|
@ -53,6 +53,7 @@ import org.sufficientlysecure.keychain.provider.KeychainExternalContract;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainExternalContract.AutocryptStatus;
|
import org.sufficientlysecure.keychain.provider.KeychainExternalContract.AutocryptStatus;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainExternalContract.EmailStatus;
|
import org.sufficientlysecure.keychain.provider.KeychainExternalContract.EmailStatus;
|
||||||
import org.sufficientlysecure.keychain.provider.SimpleContentResolverInterface;
|
import org.sufficientlysecure.keychain.provider.SimpleContentResolverInterface;
|
||||||
|
import org.sufficientlysecure.keychain.util.CloseDatabaseCursorFactory;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
public class KeychainExternalProvider extends ContentProvider implements SimpleContentResolverInterface {
|
public class KeychainExternalProvider extends ContentProvider implements SimpleContentResolverInterface {
|
||||||
|
@ -107,10 +108,6 @@ public class KeychainExternalProvider extends ContentProvider implements SimpleC
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeychainDatabase getDb() {
|
|
||||||
return new KeychainDatabase(getContext());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -146,7 +143,7 @@ public class KeychainExternalProvider extends ContentProvider implements SimpleC
|
||||||
|
|
||||||
String groupBy = null;
|
String groupBy = null;
|
||||||
|
|
||||||
SQLiteDatabase db = getDb().getReadableDatabase();
|
SQLiteDatabase db = new KeychainDatabase(getContext()).getReadableDatabase();
|
||||||
|
|
||||||
String callingPackageName = mApiPermissionHelper.getCurrentCallingPackage();
|
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);
|
Cursor cursor = qb.query(db, projection, selection, null, groupBy, null, orderBy);
|
||||||
|
qb.setCursorFactory(new CloseDatabaseCursorFactory());
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
// Tell the cursor what uri to watch, so it knows when its source data changes
|
// Tell the cursor what uri to watch, so it knows when its source data changes
|
||||||
cursor.setNotificationUri(getContext().getContentResolver(), uri);
|
cursor.setNotificationUri(getContext().getContentResolver(), uri);
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package org.sufficientlysecure.keychain.util;
|
||||||
|
|
||||||
|
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteCursor;
|
||||||
|
import android.database.sqlite.SQLiteCursorDriver;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.database.sqlite.SQLiteDatabase.CursorFactory;
|
||||||
|
import android.database.sqlite.SQLiteQuery;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
|
|
||||||
|
|
||||||
|
public class CloseDatabaseCursorFactory implements CursorFactory {
|
||||||
|
private static class CloseDatabaseCursor extends SQLiteCursor {
|
||||||
|
CloseDatabaseCursor(SQLiteDatabase db, SQLiteCursorDriver driver, String editTable, SQLiteQuery query) {
|
||||||
|
super(db, driver, editTable, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
final SQLiteDatabase db = getDatabase();
|
||||||
|
super.close();
|
||||||
|
if (db != null) {
|
||||||
|
Log.d(Constants.TAG, "Closing cursor: " + db.getPath());
|
||||||
|
try {
|
||||||
|
db.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(Constants.TAG, "Error closing db", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Cursor newCursor(SQLiteDatabase db, SQLiteCursorDriver masterQuery,
|
||||||
|
String editTable, SQLiteQuery query) {
|
||||||
|
return new CloseDatabaseCursor(db, masterQuery, editTable, query);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue