Skip to content

Commit

Permalink
Fix for concurrentmodificationexception on race condition.
Browse files Browse the repository at this point in the history
  • Loading branch information
moxie0 committed Feb 27, 2013
1 parent eb9b2ef commit 5ca7b10
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/org/thoughtcrime/securesms/service/MmsDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,28 @@ private void storeRetrievedMms(MmsDatabase mmsDatabase, DownloadItem item, Retri
}

protected void handleConnectivityChange() {
if (!isConnected()) {
if (!isConnectivityPossible() && !pendingMessages.isEmpty()) {
DatabaseFactory.getMmsDatabase(context).markDownloadState(pendingMessages.remove().getMessageId(), MmsDatabase.Types.DOWNLOAD_NO_CONNECTIVITY);
toastHandler.makeToast(context
.getString(R.string.MmsDownloader_no_connectivity_available_for_mms_download_try_again_later));
Log.w("MmsDownloadService", "Unable to download MMS, please try again later.");
finishConnectivity();
LinkedList<DownloadItem> downloadItems = (LinkedList<DownloadItem>)pendingMessages.clone();

if (isConnected()) {
pendingMessages.clear();

for (DownloadItem item : downloadItems) {
downloadMms(item);
}

return;
}
finishConnectivity();
} else if (!isConnected() && !isConnectivityPossible()) {
pendingMessages.clear();

for (DownloadItem item : pendingMessages) {
downloadMms(item);
}
for (DownloadItem item : downloadItems) {
DatabaseFactory.getMmsDatabase(context).markDownloadState(item.getMessageId(), MmsDatabase.Types.DOWNLOAD_NO_CONNECTIVITY);
}

pendingMessages.clear();
finishConnectivity();
toastHandler.makeToast(context
.getString(R.string.MmsDownloader_no_connectivity_available_for_mms_download_try_again_later));

finishConnectivity();
}
}


Expand Down

0 comments on commit 5ca7b10

Please sign in to comment.