Fix deadlock issue in AttachmentDownloadService

* When a connectivity wait was added to processQueue, I neglected
  to consider that a lock was held during this time
* The fix is to move the check for connectivity out of processQueue

Bug: 3500702

Change-Id: I646cf899ff895d9838612e89b15b66f1084840b1
This commit is contained in:
Marc Blank 2011-03-01 13:42:30 -08:00
parent 23d6be4d21
commit 81273dfcee
2 changed files with 14 additions and 4 deletions

View File

@ -142,6 +142,15 @@ public class EmailConnectivityManager extends BroadcastReceiver {
}
}
/**
* Request current connectivity status
* @return whether there is connectivity at this time
*/
public boolean hasConnectivity() {
NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
return (info != null);
}
public void waitForConnectivity() {
// If we're unregistered, throw an exception
if (!mRegistered) {

View File

@ -308,9 +308,6 @@ public class AttachmentDownloadService extends Service implements Runnable {
Log.d(TAG, "== Checking attachment queue, " + mDownloadSet.size() + " entries");
}
// Don't run unless/until we have connectivity
mConnectivityManager.waitForConnectivity();
Iterator<DownloadRequest> iterator = mDownloadSet.descendingIterator();
// First, start up any required downloads, in priority order
while (iterator.hasNext() &&
@ -412,7 +409,9 @@ public class AttachmentDownloadService extends Service implements Runnable {
}
}
// Check whether we can start new downloads...
processQueue();
if (mConnectivityManager.hasConnectivity()) {
processQueue();
}
}
/**
@ -471,6 +470,7 @@ public class AttachmentDownloadService extends Service implements Runnable {
System.currentTimeMillis() + WATCHDOG_CHECK_INTERVAL, WATCHDOG_CHECK_INTERVAL,
mWatchdogPendingIntent);
}
/*package*/ void createWatchdogPendingIntent(Context context) {
Intent alarmIntent = new Intent(context, Watchdog.class);
mWatchdogPendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0);
@ -862,6 +862,7 @@ public class AttachmentDownloadService extends Service implements Runnable {
// Loop until stopped, with a 30 minute wait loop
while (!mStop) {
// Here's where we run our attachment loading logic...
mConnectivityManager.waitForConnectivity();
mDownloadSet.processQueue();
synchronized(mLock) {
try {