Calculate available background threads for AttachmentService correctly.
Also iterated on some logging to help debug Attachment issues: Bug: 17789960 Change-Id: I77331f9a41f5c95ed228e8ca5fd36a66db5b78ee
This commit is contained in:
parent
b62067e3c3
commit
824a80491c
@ -137,8 +137,9 @@ public class AttachmentService extends Service implements Runnable {
|
|||||||
|
|
||||||
// A map of attachment ids to the number of failed attempts to download the attachment
|
// A map of attachment ids to the number of failed attempts to download the attachment
|
||||||
// NOTE: We do not want to persist this. This allows us to retry background downloading
|
// NOTE: We do not want to persist this. This allows us to retry background downloading
|
||||||
// if any transient network errors are fixed & and the app is restarted
|
// if any transient network errors are fixed and the app is restarted
|
||||||
final ConcurrentHashMap<Long, Integer> mAttachmentFailureMap = new ConcurrentHashMap<Long, Integer>();
|
final ConcurrentHashMap<Long, Integer> mAttachmentFailureMap =
|
||||||
|
new ConcurrentHashMap<Long, Integer>();
|
||||||
|
|
||||||
// Keeps tracks of downloads in progress based on an attachment ID to DownloadRequest mapping.
|
// Keeps tracks of downloads in progress based on an attachment ID to DownloadRequest mapping.
|
||||||
final ConcurrentHashMap<Long, DownloadRequest> mDownloadsInProgress =
|
final ConcurrentHashMap<Long, DownloadRequest> mDownloadsInProgress =
|
||||||
@ -699,10 +700,10 @@ public class AttachmentService extends Service implements Runnable {
|
|||||||
|
|
||||||
// In advanced debug mode, let's look at the state of all in-progress downloads
|
// In advanced debug mode, let's look at the state of all in-progress downloads
|
||||||
// after processQueue() runs.
|
// after processQueue() runs.
|
||||||
debugTrace("Downloads Map before processQueue");
|
debugTrace("In progress downloads before processQueue");
|
||||||
dumpInProgressDownloads();
|
dumpInProgressDownloads();
|
||||||
processQueue();
|
processQueue();
|
||||||
debugTrace("Downloads Map after processQueue");
|
debugTrace("In progress downloads after processQueue");
|
||||||
dumpInProgressDownloads();
|
dumpInProgressDownloads();
|
||||||
|
|
||||||
if (mDownloadQueue.isEmpty() && (mDownloadsInProgress.size() < 1)) {
|
if (mDownloadQueue.isEmpty() && (mDownloadsInProgress.size() < 1)) {
|
||||||
@ -710,7 +711,7 @@ public class AttachmentService extends Service implements Runnable {
|
|||||||
stopSelf();
|
stopSelf();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
debugTrace("Run() wait for mLock");
|
debugTrace("Run() idle, wait for mLock (something to do)");
|
||||||
synchronized(mLock) {
|
synchronized(mLock) {
|
||||||
try {
|
try {
|
||||||
mLock.wait(PROCESS_QUEUE_WAIT_TIME);
|
mLock.wait(PROCESS_QUEUE_WAIT_TIME);
|
||||||
@ -718,7 +719,7 @@ public class AttachmentService extends Service implements Runnable {
|
|||||||
// That's ok; we'll just keep looping
|
// That's ok; we'll just keep looping
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
debugTrace("Run() got mLock");
|
debugTrace("Run() got mLock (there is work to do or we timed out)");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unregister now that we're done
|
// Unregister now that we're done
|
||||||
@ -899,12 +900,13 @@ public class AttachmentService extends Service implements Runnable {
|
|||||||
|
|
||||||
// Then, try opportunistic download of appropriate attachments
|
// Then, try opportunistic download of appropriate attachments
|
||||||
final int availableBackgroundThreads =
|
final int availableBackgroundThreads =
|
||||||
MAX_SIMULTANEOUS_DOWNLOADS - mDownloadsInProgress.size() - 1;
|
MAX_SIMULTANEOUS_DOWNLOADS - mDownloadsInProgress.size();
|
||||||
if (availableBackgroundThreads < 1) {
|
if (availableBackgroundThreads < 1) {
|
||||||
// We want to leave one spot open for a user requested download that we haven't
|
// We want to leave one spot open for a user requested download that we haven't
|
||||||
// started processing yet.
|
// started processing yet.
|
||||||
LogUtils.d(LOG_TAG, "Skipping opportunistic downloads, %d threads available",
|
LogUtils.d(LOG_TAG, "Skipping opportunistic downloads, %d threads available",
|
||||||
availableBackgroundThreads);
|
availableBackgroundThreads);
|
||||||
|
dumpInProgressDownloads();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1289,6 +1291,7 @@ public class AttachmentService extends Service implements Runnable {
|
|||||||
if (ENABLE_ATTACHMENT_SERVICE_DEBUG < 1) {
|
if (ENABLE_ATTACHMENT_SERVICE_DEBUG < 1) {
|
||||||
LogUtils.d(LOG_TAG, "Advanced logging not configured.");
|
LogUtils.d(LOG_TAG, "Advanced logging not configured.");
|
||||||
}
|
}
|
||||||
|
LogUtils.d(LOG_TAG, "Here are the in-progress downloads...");
|
||||||
for (final DownloadRequest req : mDownloadsInProgress.values()) {
|
for (final DownloadRequest req : mDownloadsInProgress.values()) {
|
||||||
LogUtils.d(LOG_TAG, "--BEGIN DownloadRequest DUMP--");
|
LogUtils.d(LOG_TAG, "--BEGIN DownloadRequest DUMP--");
|
||||||
LogUtils.d(LOG_TAG, "Account: #%d", req.mAccountId);
|
LogUtils.d(LOG_TAG, "Account: #%d", req.mAccountId);
|
||||||
@ -1309,6 +1312,7 @@ public class AttachmentService extends Service implements Runnable {
|
|||||||
LogUtils.d(LOG_TAG, "Last Callback Time: %d", req.mLastCallbackTime);
|
LogUtils.d(LOG_TAG, "Last Callback Time: %d", req.mLastCallbackTime);
|
||||||
LogUtils.d(LOG_TAG, "------------------------------");
|
LogUtils.d(LOG_TAG, "------------------------------");
|
||||||
}
|
}
|
||||||
|
LogUtils.d(LOG_TAG, "Done reporting in-progress downloads...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user