summaryrefslogtreecommitdiffstats
path: root/ui/src/com/android/providers/downloads/ui
diff options
context:
space:
mode:
authorSteve Howard <showard@google.com>2010-09-29 16:48:01 -0700
committerSteve Howard <showard@google.com>2010-09-29 17:34:52 -0700
commitb108a273b150e81bf26553b8851d6241bc711f98 (patch)
tree51f469e8e8d3d600f4bf279ec6c08f714fef2ae6 /ui/src/com/android/providers/downloads/ui
parent69784dc727df4f79ceff2ca88d4c79a98583c5b0 (diff)
downloadandroid_packages_providers_DownloadProvider-b108a273b150e81bf26553b8851d6241bc711f98.tar.gz
android_packages_providers_DownloadProvider-b108a273b150e81bf26553b8851d6241bc711f98.tar.bz2
android_packages_providers_DownloadProvider-b108a273b150e81bf26553b8851d6241bc711f98.zip
Improve how the download manager reports paused statuses.
This change makes the download manager report more detail when a download is paused. Rather than always reporting status RUNNING_PAUSED, there are now four different statuses: * paused by the app * waiting to retry after a network error * waiting for network connectivity * queued for wifi due to size limits This allows a few improvements: * code deciding when to run a download can be improved and cleaned up (I've taken some extra steps in cleaning up this particular code) * notification code no longer has to rely on the in-memory-only "mPausedReason" member of DownloadInfo; instead, it knows from the status that the download is queued for wifi, and can display the appropriate string. This moves the string fetching out into the UI-specific logic and is a sign that this is really the right way to do things. And finally, the real motivation for this change: I've changed the meaning of "Queued" in the downloads UI so it now means "Queued for WiFi'. This is what was originally intended, I'd misunderstood. What was formerly known as "Queued", a download that hadn't started, is now displayed as "In progress" (it's always a transient state so it's basically meaningless anyway). Otherwise it remains the same (in particular, downloads paused for other reasons are still reported as "In progress"). I've also increased some of the logging in DownloadThread a bit, as this change initally introduced some bugs that were impossible to track down without that logging. There have been other bug reports that were impossible to diagnose and these few extra log statements should really help, without cluttering logs too much. I've taken care to avoid potentially introducing any PII into the logs. Change-Id: Id0b8d65fc8e4406ad7ffa1439ffc22a0281b051f
Diffstat (limited to 'ui/src/com/android/providers/downloads/ui')
-rw-r--r--ui/src/com/android/providers/downloads/ui/DownloadAdapter.java12
-rw-r--r--ui/src/com/android/providers/downloads/ui/DownloadList.java52
2 files changed, 40 insertions, 24 deletions
diff --git a/ui/src/com/android/providers/downloads/ui/DownloadAdapter.java b/ui/src/com/android/providers/downloads/ui/DownloadAdapter.java
index c7d4c2cb..9c572538 100644
--- a/ui/src/com/android/providers/downloads/ui/DownloadAdapter.java
+++ b/ui/src/com/android/providers/downloads/ui/DownloadAdapter.java
@@ -57,6 +57,7 @@ public class DownloadAdapter extends CursorAdapter {
private int mTitleColumnId;
private int mDescriptionColumnId;
private int mStatusColumnId;
+ private int mReasonColumnId;
private int mTotalBytesColumnId;
private int mMediaTypeColumnId;
private int mDateColumnId;
@@ -76,6 +77,7 @@ public class DownloadAdapter extends CursorAdapter {
mTitleColumnId = cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TITLE);
mDescriptionColumnId = cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_DESCRIPTION);
mStatusColumnId = cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS);
+ mReasonColumnId = cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_REASON);
mTotalBytesColumnId = cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES);
mMediaTypeColumnId = cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_MEDIA_TYPE);
mDateColumnId =
@@ -150,11 +152,15 @@ public class DownloadAdapter extends CursorAdapter {
return R.string.download_success;
case DownloadManager.STATUS_PENDING:
- return R.string.download_pending;
-
case DownloadManager.STATUS_RUNNING:
- case DownloadManager.STATUS_PAUSED:
return R.string.download_running;
+
+ case DownloadManager.STATUS_PAUSED:
+ if (mCursor.getInt(mReasonColumnId) == DownloadManager.PAUSED_QUEUED_FOR_WIFI) {
+ return R.string.download_queued;
+ } else {
+ return R.string.download_running;
+ }
}
throw new IllegalStateException("Unknown status: " + mCursor.getInt(mStatusColumnId));
}
diff --git a/ui/src/com/android/providers/downloads/ui/DownloadList.java b/ui/src/com/android/providers/downloads/ui/DownloadList.java
index 4b3547c2..bb331534 100644
--- a/ui/src/com/android/providers/downloads/ui/DownloadList.java
+++ b/ui/src/com/android/providers/downloads/ui/DownloadList.java
@@ -85,7 +85,7 @@ public class DownloadList extends Activity
private int mIdColumnId;
private int mLocalUriColumnId;
private int mMediaTypeColumnId;
- private int mErrorCodeColumndId;
+ private int mReasonColumndId;
private boolean mIsSortedBySize = false;
private Set<Long> mSelectedIds = new HashSet<Long>();
@@ -94,8 +94,9 @@ public class DownloadList extends Activity
* We keep track of when a dialog is being displayed for a pending download, because if that
* download starts running, we want to immediately hide the dialog.
*/
- private Long mPendingDownloadId = null;
- private AlertDialog mPendingDialog;
+ private Long mQueuedDownloadId = null;
+ private AlertDialog mQueuedDialog;
+
private class MyContentObserver extends ContentObserver {
public MyContentObserver() {
@@ -145,8 +146,8 @@ public class DownloadList extends Activity
mDateSortedCursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI);
mMediaTypeColumnId =
mDateSortedCursor.getColumnIndexOrThrow(DownloadManager.COLUMN_MEDIA_TYPE);
- mErrorCodeColumndId =
- mDateSortedCursor.getColumnIndexOrThrow(DownloadManager.COLUMN_ERROR_CODE);
+ mReasonColumndId =
+ mDateSortedCursor.getColumnIndexOrThrow(DownloadManager.COLUMN_REASON);
mDateSortedAdapter = new DateSortedDownloadAdapter(this, mDateSortedCursor, this);
mDateOrderedListView.setAdapter(mDateSortedAdapter);
@@ -359,19 +360,23 @@ public class DownloadList extends Activity
long id = cursor.getInt(mIdColumnId);
switch (cursor.getInt(mStatusColumnId)) {
case DownloadManager.STATUS_PENDING:
- mPendingDownloadId = id;
- mPendingDialog = new AlertDialog.Builder(this)
- .setTitle(R.string.dialog_title_not_available)
- .setMessage(R.string.dialog_queued_body)
- .setPositiveButton(R.string.keep_queued_download, null)
- .setNegativeButton(R.string.remove_download, getDeleteClickHandler(id))
- .setOnCancelListener(this)
- .show();
+ case DownloadManager.STATUS_RUNNING:
+ sendRunningDownloadClickedBroadcast(id);
break;
- case DownloadManager.STATUS_RUNNING:
case DownloadManager.STATUS_PAUSED:
- sendRunningDownloadClickedBroadcast(id);
+ if (isPausedForWifi(cursor)) {
+ mQueuedDownloadId = id;
+ mQueuedDialog = new AlertDialog.Builder(this)
+ .setTitle(R.string.dialog_title_not_available)
+ .setMessage(R.string.dialog_queued_body)
+ .setPositiveButton(R.string.keep_queued_download, null)
+ .setNegativeButton(R.string.remove_download, getDeleteClickHandler(id))
+ .setOnCancelListener(this)
+ .show();
+ } else {
+ sendRunningDownloadClickedBroadcast(id);
+ }
break;
case DownloadManager.STATUS_SUCCESSFUL:
@@ -388,7 +393,7 @@ public class DownloadList extends Activity
* @return the appropriate error message for the failed download pointed to by cursor
*/
private String getErrorMessage(Cursor cursor) {
- switch (cursor.getInt(mErrorCodeColumndId)) {
+ switch (cursor.getInt(mReasonColumndId)) {
case DownloadManager.ERROR_FILE_ALREADY_EXISTS:
if (isOnExternalStorage(cursor)) {
return getString(R.string.dialog_file_already_exists);
@@ -616,13 +621,18 @@ public class DownloadList extends Activity
void handleDownloadsChanged() {
checkSelectionForDeletedEntries();
- if (mPendingDownloadId != null && moveToDownload(mPendingDownloadId)) {
- if (mDateSortedCursor.getInt(mStatusColumnId) != DownloadManager.STATUS_PENDING) {
- mPendingDialog.cancel();
+ if (mQueuedDownloadId != null && moveToDownload(mQueuedDownloadId)) {
+ if (mDateSortedCursor.getInt(mStatusColumnId) != DownloadManager.STATUS_PAUSED
+ || !isPausedForWifi(mDateSortedCursor)) {
+ mQueuedDialog.cancel();
}
}
}
+ private boolean isPausedForWifi(Cursor cursor) {
+ return cursor.getInt(mReasonColumndId) == DownloadManager.PAUSED_QUEUED_FOR_WIFI;
+ }
+
/**
* Check if any of the selected downloads have been deleted from the downloads database, and
* remove such downloads from the selection.
@@ -662,7 +672,7 @@ public class DownloadList extends Activity
*/
@Override
public void onCancel(DialogInterface dialog) {
- mPendingDownloadId = null;
- mPendingDialog = null;
+ mQueuedDownloadId = null;
+ mQueuedDialog = null;
}
}