Remove UnavailableStorageException

This commit is contained in:
cketti 2021-09-17 11:02:54 +02:00
parent 0167d8dfef
commit 18fbb45352
7 changed files with 29 additions and 85 deletions

View file

@ -578,7 +578,7 @@ public class LocalFolder {
try {
return this.localStore.getDatabase().execute(false, new DbCallback<String>() {
@Override
public String doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
public String doDbWork(final SQLiteDatabase db) throws WrappedException {
try {
open();
Cursor cursor = null;
@ -608,7 +608,7 @@ public class LocalFolder {
try {
return this.localStore.getDatabase().execute(false, new DbCallback<LocalMessage>() {
@Override
public LocalMessage doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
public LocalMessage doDbWork(final SQLiteDatabase db) throws WrappedException {
try {
open();
LocalMessage message = new LocalMessage(LocalFolder.this.localStore, uid, LocalFolder.this);
@ -679,7 +679,7 @@ public class LocalFolder {
try {
return localStore.getDatabase().execute(false, new DbCallback<List<LocalMessage>>() {
@Override
public List<LocalMessage> doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
public List<LocalMessage> doDbWork(final SQLiteDatabase db) throws WrappedException {
try {
open();
return LocalFolder.this.localStore.getMessages(listener, LocalFolder.this,
@ -705,7 +705,7 @@ public class LocalFolder {
try {
return localStore.getDatabase().execute(false, new DbCallback<List<String>>() {
@Override
public List<String> doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
public List<String> doDbWork(final SQLiteDatabase db) throws WrappedException {
Cursor cursor = null;
ArrayList<String> result = new ArrayList<>();
@ -777,7 +777,7 @@ public class LocalFolder {
try {
this.localStore.getDatabase().execute(true, new DbCallback<Void>() {
@Override
public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
public Void doDbWork(final SQLiteDatabase db) throws WrappedException {
for (LocalMessage message : messages) {
try {
message.destroy();
@ -974,7 +974,7 @@ public class LocalFolder {
localStore.getDatabase().execute(false, new DbCallback<Void>() {
@Override
public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
public Void doDbWork(final SQLiteDatabase db) throws WrappedException {
long messagePartId;
Cursor cursor = db.query("message_parts", new String[] { "id" }, "root = ? AND server_extra = ?",
@ -1013,7 +1013,7 @@ public class LocalFolder {
cv.put("uid", message.getUid());
this.localStore.getDatabase().execute(false, new DbCallback<Void>() {
@Override
public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
public Void doDbWork(final SQLiteDatabase db) throws WrappedException {
db.update("messages", cv, "id = ?", new String[]
{ Long.toString(message.getDatabaseId()) });
return null;
@ -1032,8 +1032,7 @@ public class LocalFolder {
try {
this.localStore.getDatabase().execute(true, new DbCallback<Void>() {
@Override
public Void doDbWork(final SQLiteDatabase db) throws WrappedException,
UnavailableStorageException {
public Void doDbWork(final SQLiteDatabase db) throws WrappedException {
for (LocalMessage message : messages) {
try {
@ -1167,8 +1166,7 @@ public class LocalFolder {
try {
localStore.getDatabase().execute(true, new DbCallback<Void>() {
@Override
public Void doDbWork(final SQLiteDatabase db) throws WrappedException,
UnavailableStorageException {
public Void doDbWork(final SQLiteDatabase db) throws WrappedException {
try {
deleteMessagePartsAndDataFromDisk(messagePartId);
@ -1301,7 +1299,7 @@ public class LocalFolder {
private void deleteMessageParts(final long rootMessagePartId) throws MessagingException {
localStore.getDatabase().execute(false, new DbCallback<Void>() {
@Override
public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
public Void doDbWork(final SQLiteDatabase db) throws WrappedException {
db.delete("message_parts", "root = ?", new String[] { Long.toString(rootMessagePartId) });
return null;
}
@ -1311,7 +1309,7 @@ public class LocalFolder {
private void deleteMessageDataFromDisk(final long rootMessagePartId) throws MessagingException {
localStore.getDatabase().execute(false, new DbCallback<Void>() {
@Override
public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
public Void doDbWork(final SQLiteDatabase db) throws WrappedException {
deleteMessagePartsFromDisk(db, rootMessagePartId);
return null;
}

View file

@ -270,7 +270,7 @@ public class LocalMessage extends MimeMessage {
try {
this.localStore.getDatabase().execute(true, new DbCallback<Void>() {
@Override
public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
public Void doDbWork(final SQLiteDatabase db) throws WrappedException {
try {
if (flag == Flag.DELETED && set) {
delete();
@ -310,7 +310,7 @@ public class LocalMessage extends MimeMessage {
try {
localStore.getDatabase().execute(true, new DbCallback<Void>() {
@Override
public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
public Void doDbWork(final SQLiteDatabase db) throws WrappedException {
ContentValues cv = new ContentValues();
cv.put("deleted", 1);
cv.put("preview_type", DatabasePreviewType.fromPreviewType(PreviewType.NONE).getDatabaseValue());

View file

@ -51,7 +51,6 @@ import com.fsck.k9.mailstore.LockableDatabase.DbCallback;
import com.fsck.k9.mailstore.LockableDatabase.SchemaDefinition;
import com.fsck.k9.mailstore.LockableDatabase.WrappedException;
import com.fsck.k9.mailstore.StorageManager.InternalStorageProvider;
import com.fsck.k9.mailstore.StorageManager.StorageProvider;
import com.fsck.k9.message.extractors.AttachmentInfoExtractor;
import com.fsck.k9.provider.EmailProvider;
import com.fsck.k9.provider.EmailProvider.MessageColumns;
@ -180,7 +179,6 @@ public class LocalStore {
/**
* local://localhost/path/to/database/uuid.db
* This constructor is only used by {@link LocalStoreProvider#getInstance(Account)}
* @throws UnavailableStorageException if not {@link StorageProvider#isReady(Context)}
*/
private LocalStore(final Account account, final Context context) throws MessagingException {
this.context = context;
@ -282,7 +280,7 @@ public class LocalStore {
return folders;
}
public void delete() throws UnavailableStorageException {
public void delete() {
database.delete();
}
@ -809,8 +807,7 @@ public class LocalStore {
try {
database.execute(true, new DbCallback<Void>() {
@Override
public Void doDbWork(final SQLiteDatabase db) throws WrappedException,
UnavailableStorageException {
public Void doDbWork(final SQLiteDatabase db) throws WrappedException {
selectionCallback.doDbWork(db, selection.toString(),
selectionArgs.toArray(new String[selectionArgs.size()]));
@ -860,8 +857,7 @@ public class LocalStore {
* @param selectionArgs
* The current subset of the argument list.
*/
void doDbWork(SQLiteDatabase db, String selectionSet, String[] selectionArgs)
throws UnavailableStorageException;
void doDbWork(SQLiteDatabase db, String selectionSet, String[] selectionArgs);
/**
* This will be executed after each invocation of
@ -905,8 +901,7 @@ public class LocalStore {
}
@Override
public void doDbWork(SQLiteDatabase db, String selectionSet, String[] selectionArgs)
throws UnavailableStorageException {
public void doDbWork(SQLiteDatabase db, String selectionSet, String[] selectionArgs) {
db.update("messages", cv, "empty = 0 AND id" + selectionSet,
selectionArgs);
@ -952,8 +947,7 @@ public class LocalStore {
}
@Override
public void doDbWork(SQLiteDatabase db, String selectionSet, String[] selectionArgs)
throws UnavailableStorageException {
public void doDbWork(SQLiteDatabase db, String selectionSet, String[] selectionArgs) {
db.execSQL("UPDATE messages SET " + flagColumn + " = " + ((newState) ? "1" : "0") +
" WHERE id IN (" +
@ -1003,8 +997,7 @@ public class LocalStore {
}
@Override
public void doDbWork(SQLiteDatabase db, String selectionSet, String[] selectionArgs)
throws UnavailableStorageException {
public void doDbWork(SQLiteDatabase db, String selectionSet, String[] selectionArgs) {
if (threadedList) {
String sql = "SELECT m.uid, m.folder_id " +

View file

@ -35,7 +35,6 @@ public class LockableDatabase {
* @return Any relevant data. Can be <code>null</code>.
* @throws WrappedException
* @throws com.fsck.k9.mail.MessagingException
* @throws com.fsck.k9.mailstore.UnavailableStorageException
*/
T doDbWork(SQLiteDatabase db) throws WrappedException, MessagingException;
}
@ -173,7 +172,6 @@ public class LockableDatabase {
* @param callback
* Never <code>null</code>.
* @return Whatever {@link DbCallback#doDbWork(SQLiteDatabase)} returns.
* @throws UnavailableStorageException
*/
public <T> T execute(final boolean transactional, final DbCallback<T> callback) throws MessagingException {
lockRead();
@ -260,7 +258,7 @@ public class LockableDatabase {
}
}
public void open() throws UnavailableStorageException {
public void open() {
lockWrite();
try {
openOrCreateDataspace();
@ -269,12 +267,7 @@ public class LockableDatabase {
}
}
/**
*
* @throws UnavailableStorageException
*/
private void openOrCreateDataspace() throws UnavailableStorageException {
private void openOrCreateDataspace() {
lockWrite();
try {
final File databaseFile = prepareStorage(mStorageProviderId);
@ -310,13 +303,7 @@ public class LockableDatabase {
}
}
/**
* @param providerId
* Never <code>null</code>.
* @return DB file.
* @throws UnavailableStorageException
*/
protected File prepareStorage(final String providerId) throws UnavailableStorageException {
protected File prepareStorage(final String providerId) {
final StorageManager storageManager = getStorageManager();
final File databaseFile = storageManager.getDatabase(uUid, providerId);
@ -328,8 +315,7 @@ public class LockableDatabase {
}
if (!databaseParentDir.exists()) {
if (!databaseParentDir.mkdirs()) {
// Android seems to be unmounting the storage...
throw new UnavailableStorageException("Unable to access: " + databaseParentDir);
throw new RuntimeException("Unable to access: " + databaseParentDir);
}
FileHelper.touchFile(databaseParentDir, ".nomedia");
}
@ -350,23 +336,20 @@ public class LockableDatabase {
/**
* Delete the backing database.
*
* @throws UnavailableStorageException
*/
public void delete() throws UnavailableStorageException {
public void delete() {
delete(false);
}
public void recreate() throws UnavailableStorageException {
public void recreate() {
delete(true);
}
/**
* @param recreate
* <code>true</code> if the DB should be recreated after delete
* @throws UnavailableStorageException
*/
private void delete(final boolean recreate) throws UnavailableStorageException {
private void delete(final boolean recreate) {
lockWrite();
try {
try {

View file

@ -1,17 +0,0 @@
package com.fsck.k9.mailstore;
import com.fsck.k9.mail.MessagingException;
public class UnavailableStorageException extends MessagingException {
private static final long serialVersionUID = 1348267375054620792L;
public UnavailableStorageException(String message) {
// consider this exception as a permanent failure by default
this(message, true);
}
public UnavailableStorageException(String message, boolean perm) {
super(message, perm);
}
}

View file

@ -28,7 +28,6 @@ import com.fsck.k9.mailstore.LocalStoreProvider;
import com.fsck.k9.mailstore.LockableDatabase;
import com.fsck.k9.mailstore.LockableDatabase.DbCallback;
import com.fsck.k9.mailstore.LockableDatabase.WrappedException;
import com.fsck.k9.mailstore.UnavailableStorageException;
import com.fsck.k9.search.SqlQueryBuilder;
@ -277,8 +276,7 @@ public class EmailProvider extends ContentProvider {
try {
return database.execute(false, new DbCallback<Cursor>() {
@Override
public Cursor doDbWork(SQLiteDatabase db) throws WrappedException,
UnavailableStorageException {
public Cursor doDbWork(SQLiteDatabase db) throws WrappedException {
String where;
if (TextUtils.isEmpty(selection)) {
@ -326,8 +324,6 @@ public class EmailProvider extends ContentProvider {
return cursor;
}
});
} catch (UnavailableStorageException e) {
throw new RuntimeException("Storage not available", e);
} catch (MessagingException e) {
throw new RuntimeException("messaging exception", e);
}
@ -342,8 +338,7 @@ public class EmailProvider extends ContentProvider {
try {
return database.execute(false, new DbCallback<Cursor>() {
@Override
public Cursor doDbWork(SQLiteDatabase db) throws WrappedException,
UnavailableStorageException {
public Cursor doDbWork(SQLiteDatabase db) throws WrappedException {
StringBuilder query = new StringBuilder();
@ -401,8 +396,6 @@ public class EmailProvider extends ContentProvider {
return db.rawQuery(query.toString(), selectionArgs);
}
});
} catch (UnavailableStorageException e) {
throw new RuntimeException("Storage not available", e);
} catch (MessagingException e) {
throw new RuntimeException("messaging exception", e);
}
@ -469,8 +462,7 @@ public class EmailProvider extends ContentProvider {
try {
return database.execute(false, new DbCallback<Cursor>() {
@Override
public Cursor doDbWork(SQLiteDatabase db) throws WrappedException,
UnavailableStorageException {
public Cursor doDbWork(SQLiteDatabase db) throws WrappedException {
StringBuilder query = new StringBuilder();
query.append("SELECT ");
@ -507,8 +499,6 @@ public class EmailProvider extends ContentProvider {
return db.rawQuery(query.toString(), new String[] { threadId });
}
});
} catch (UnavailableStorageException e) {
throw new RuntimeException("Storage not available", e);
} catch (MessagingException e) {
throw new RuntimeException("messaging exception", e);
}

View file

@ -16,7 +16,6 @@ import com.fsck.k9.DI;
import com.fsck.k9.K9;
import com.fsck.k9.Preferences;
import com.fsck.k9.mailstore.LocalStoreProvider;
import com.fsck.k9.mailstore.UnavailableStorageException;
import com.fsck.k9.power.TracingPowerManager;
import com.fsck.k9.power.TracingPowerManager.TracingWakeLock;
import timber.log.Timber;
@ -195,8 +194,6 @@ public class DatabaseUpgradeService extends Service {
try {
// Account.getLocalStore() is blocking and will upgrade the database if necessary
DI.get(LocalStoreProvider.class).getInstance(account);
} catch (UnavailableStorageException e) {
Timber.e("Database unavailable");
} catch (Exception e) {
Timber.e(e, "Error while upgrading database");
}