Fixed rare crash

pull/172/head
M66B 5 years ago
parent fd497698ab
commit c95dabd05b

@ -65,6 +65,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
import javax.mail.AuthenticationFailedException; import javax.mail.AuthenticationFailedException;
import javax.mail.Folder; import javax.mail.Folder;
@ -1185,83 +1186,88 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
" operations=" + partitions.get(key).size()); " operations=" + partitions.get(key).size());
} }
executor.submit(new Helper.PriorityRunnable(key.getPriority()) { try {
@Override executor.submit(new Helper.PriorityRunnable(key.getPriority()) {
public void run() { @Override
super.run(); public void run() {
try { super.run();
wlFolder.acquire(); try {
wlFolder.acquire();
List<TupleOperationEx> partition;
synchronized (partitions) {
partition = partitions.get(key);
partitions.remove(key);
}
Log.i(folder.name + List<TupleOperationEx> partition;
" executing partition=" + key + synchronized (partitions) {
" operations=" + partition.size()); partition = partitions.get(key);
partitions.remove(key);
}
// Get folder Log.i(folder.name +
Folder ifolder = mapFolders.get(folder); // null when polling " executing partition=" + key +
boolean canOpen = (account.protocol == EntityAccount.TYPE_IMAP || EntityFolder.INBOX.equals(folder.type)); " operations=" + partition.size());
final boolean shouldClose = (ifolder == null && canOpen);
try { // Get folder
Log.i(folder.name + " run " + (shouldClose ? "offline" : "online")); Folder ifolder = mapFolders.get(folder); // null when polling
boolean canOpen = (account.protocol == EntityAccount.TYPE_IMAP || EntityFolder.INBOX.equals(folder.type));
final boolean shouldClose = (ifolder == null && canOpen);
if (shouldClose) { try {
// Prevent unnecessary folder connections Log.i(folder.name + " run " + (shouldClose ? "offline" : "online"));
if (db.operation().getOperationCount(folder.id, null) == 0)
return;
db.folder().setFolderState(folder.id, "connecting"); if (shouldClose) {
// Prevent unnecessary folder connections
if (db.operation().getOperationCount(folder.id, null) == 0)
return;
ifolder = iservice.getStore().getFolder(folder.name); db.folder().setFolderState(folder.id, "connecting");
ifolder.open(Folder.READ_WRITE);
db.folder().setFolderState(folder.id, "connected"); ifolder = iservice.getStore().getFolder(folder.name);
ifolder.open(Folder.READ_WRITE);
db.folder().setFolderError(folder.id, null); db.folder().setFolderState(folder.id, "connected");
}
Core.processOperations(ServiceSynchronize.this, db.folder().setFolderError(folder.id, null);
account, folder, }
partition,
iservice.getStore(), ifolder, Core.processOperations(ServiceSynchronize.this,
state); account, folder,
partition,
} catch (FolderNotFoundException ex) { iservice.getStore(), ifolder,
Log.w(folder.name, ex); state);
db.folder().deleteFolder(folder.id);
} catch (Throwable ex) { } catch (FolderNotFoundException ex) {
Log.e(folder.name, ex); Log.w(folder.name, ex);
EntityLog.log( db.folder().deleteFolder(folder.id);
ServiceSynchronize.this, } catch (Throwable ex) {
folder.name + " " + Log.formatThrowable(ex, false)); Log.e(folder.name, ex);
db.folder().setFolderError(folder.id, Log.formatThrowable(ex)); EntityLog.log(
state.error(ex); ServiceSynchronize.this,
} finally { folder.name + " " + Log.formatThrowable(ex, false));
if (shouldClose) { db.folder().setFolderError(folder.id, Log.formatThrowable(ex));
if (ifolder != null && ifolder.isOpen()) { state.error(ex);
db.folder().setFolderState(folder.id, "closing"); } finally {
try { if (shouldClose) {
ifolder.close(false); if (ifolder != null && ifolder.isOpen()) {
} catch (MessagingException ex) { db.folder().setFolderState(folder.id, "closing");
Log.w(folder.name, ex); try {
ifolder.close(false);
} catch (MessagingException ex) {
Log.w(folder.name, ex);
}
} }
if (folder.synchronize && (folder.poll || !capIdle))
db.folder().setFolderState(folder.id, "waiting");
else
db.folder().setFolderState(folder.id, null);
} }
if (folder.synchronize && (folder.poll || !capIdle))
db.folder().setFolderState(folder.id, "waiting");
else
db.folder().setFolderState(folder.id, null);
} }
} finally {
wlFolder.release();
} }
} finally {
wlFolder.release();
} }
} });
}); } catch (RejectedExecutionException ex) {
Log.w(ex);
break;
}
} }
} }
} }

Loading…
Cancel
Save