Skip to content

Commit

Permalink
Download: Add support to manually pause/resume download
Browse files Browse the repository at this point in the history
Add the pause and resume APIs here so that applications can
pause and resume downloads manually through DownloadManager.

This patch consists of 2 changes:
1. Add pause and resume download APIs
2. Add another paused reason for this download status

Change-Id: I606b48ca20f43bcc6c119683818c2ab6ff03bfe5
  • Loading branch information
qqzhou authored and sayeed99 committed May 18, 2017
1 parent 6e895ba commit dfe7624
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
40 changes: 40 additions & 0 deletions core/java/android/app/DownloadManager.java
Expand Up @@ -280,6 +280,13 @@ public class DownloadManager {
*/
public final static int PAUSED_UNKNOWN = 4;

/**
* Value of {@link #COLUMN_REASON} when the download is paused manually.
*
* @hide
*/
public final static int PAUSED_MANUAL = 5;

/**
* Broadcast intent action sent by the download manager when a download completes.
*/
Expand Down Expand Up @@ -922,6 +929,7 @@ Cursor runQuery(ContentResolver resolver, String[] projection, Uri baseUri) {
parts.add(statusClause("=", Downloads.Impl.STATUS_WAITING_TO_RETRY));
parts.add(statusClause("=", Downloads.Impl.STATUS_WAITING_FOR_NETWORK));
parts.add(statusClause("=", Downloads.Impl.STATUS_QUEUED_FOR_WIFI));
parts.add(statusClause("=", Downloads.Impl.STATUS_PAUSED_MANUAL));
}
if ((mStatusFlags & STATUS_SUCCESSFUL) != 0) {
parts.add(statusClause("=", Downloads.Impl.STATUS_SUCCESS));
Expand Down Expand Up @@ -1172,6 +1180,34 @@ public void forceDownload(long... ids) {
mResolver.update(mBaseUri, values, getWhereClauseForIds(ids), getWhereArgsForIds(ids));
}

/**
* Pause the given running download manually.
*
* @param id the ID of the download to be paused
* @return the number of downloads actually updated
* @hide
*/
public int pauseDownload(long id) {
ContentValues values = new ContentValues();
values.put(Downloads.Impl.COLUMN_STATUS, Downloads.Impl.STATUS_PAUSED_MANUAL);

return mResolver.update(ContentUris.withAppendedId(mBaseUri, id), values, null, null);
}

/**
* Resume the given paused download manually.
*
* @param id the ID of the download to be resumed
* @return the number of downloads actually updated
* @hide
*/
public int resumeDownload(long id) {
ContentValues values = new ContentValues();
values.put(Downloads.Impl.COLUMN_STATUS, Downloads.Impl.STATUS_RUNNING);

return mResolver.update(ContentUris.withAppendedId(mBaseUri, id), values, null, null);
}

/**
* Returns maximum size, in bytes, of downloads that may go over a mobile connection; or null if
* there's no limit
Expand Down Expand Up @@ -1546,6 +1582,9 @@ private long getPausedReason(int status) {
case Downloads.Impl.STATUS_QUEUED_FOR_WIFI:
return PAUSED_QUEUED_FOR_WIFI;

case Downloads.Impl.STATUS_PAUSED_MANUAL:
return PAUSED_MANUAL;

default:
return PAUSED_UNKNOWN;
}
Expand Down Expand Up @@ -1601,6 +1640,7 @@ private int translateStatus(int status) {
case Downloads.Impl.STATUS_WAITING_TO_RETRY:
case Downloads.Impl.STATUS_WAITING_FOR_NETWORK:
case Downloads.Impl.STATUS_QUEUED_FOR_WIFI:
case Downloads.Impl.STATUS_PAUSED_MANUAL:
return STATUS_PAUSED;

case Downloads.Impl.STATUS_SUCCESS:
Expand Down
5 changes: 5 additions & 0 deletions core/java/android/provider/Downloads.java
Expand Up @@ -599,6 +599,11 @@ public static boolean isStatusCompleted(int status) {
*/
public static final int STATUS_QUEUED_FOR_WIFI = 196;

/**
* This download is paused manually.
*/
public static final int STATUS_PAUSED_MANUAL = 197;

/**
* This download couldn't be completed due to insufficient storage
* space. Typically, this is because the SD card is full.
Expand Down

0 comments on commit dfe7624

Please sign in to comment.