1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-15 14:05:05 -05:00

use the new way on internal storage, or the original way otherwise

This commit is contained in:
ashley willis 2012-05-08 18:29:23 -05:00
parent f5461e2fe4
commit 321fbe614d

View File

@ -371,12 +371,24 @@ public class LockableDatabase {
try { try {
final File databaseFile = prepareStorage(mStorageProviderId); final File databaseFile = prepareStorage(mStorageProviderId);
try { try {
mDb = application.openOrCreateDatabase(databaseFile.getName(), Context.MODE_PRIVATE, null); if (StorageManager.InternalStorageProvider.ID.equals(mStorageProviderId)) {
// internal storage
mDb = application.openOrCreateDatabase(databaseFile.getName(), Context.MODE_PRIVATE, null);
} else {
// external storage
mDb = SQLiteDatabase.openOrCreateDatabase(databaseFile, null);
}
} catch (SQLiteException e) { } catch (SQLiteException e) {
// try to gracefully handle DB corruption - see issue 2537 // try to gracefully handle DB corruption - see issue 2537
Log.w(K9.LOG_TAG, "Unable to open DB " + databaseFile + " - removing file and retrying", e); Log.w(K9.LOG_TAG, "Unable to open DB " + databaseFile + " - removing file and retrying", e);
databaseFile.delete(); databaseFile.delete();
mDb = application.openOrCreateDatabase(databaseFile.getName(), Context.MODE_PRIVATE, null); if (StorageManager.InternalStorageProvider.ID.equals(mStorageProviderId)) {
// internal storage
mDb = application.openOrCreateDatabase(databaseFile.getName(), Context.MODE_PRIVATE, null);
} else {
// external storage
mDb = SQLiteDatabase.openOrCreateDatabase(databaseFile, null);
}
} }
if (mDb.getVersion() != mSchemaDefinition.getVersion()) { if (mDb.getVersion() != mSchemaDefinition.getVersion()) {
mSchemaDefinition.doDbUpgrade(mDb); mSchemaDefinition.doDbUpgrade(mDb);