Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8826b515 authored by qqzhou's avatar qqzhou Committed by Linux Build Service Account
Browse files

DownloadManager: add to pause/resume download by user

We add pause and resume APIs here to make application can
pause and resume downloads by DownloadManager.

Code change contains:
  - add pause and resume download APIs.
  - add another paused status for this case.

Change-Id: I5bf4f15b2464009595f7926522ca6d5f1b0e2b8d
parent a3fc9756
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -266,6 +266,13 @@ public class DownloadManager {
     */
    public final static int PAUSED_UNKNOWN = 4;

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

    /**
     * Broadcast intent action sent by the download manager when a download completes.
     */
@@ -865,6 +872,7 @@ public class DownloadManager {
                    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_BY_USER));
                }
                if ((mStatusFlags & STATUS_SUCCESSFUL) != 0) {
                    parts.add(statusClause("=", Downloads.Impl.STATUS_SUCCESS));
@@ -1120,6 +1128,30 @@ public class DownloadManager {
        mResolver.update(mBaseUri, values, getWhereClauseForIds(ids), getWhereArgsForIds(ids));
    }

    /**
     * Pause the given running download by user.
     *
     * @param id the ID of the download to be paused
     * @hide
     */
    public void pauseDownload(long id) {
        ContentValues values = new ContentValues();
        values.put(Downloads.Impl.COLUMN_STATUS, Downloads.Impl.STATUS_PAUSED_BY_USER);
        mResolver.update(ContentUris.withAppendedId(mBaseUri, id), values, null, null);
    }

    /**
     * Resume the given paused download by user.
     *
     * @param id the ID of the download to be resumed
     * @hide
     */
    public void resumeDownload(long id) {
       ContentValues values = new ContentValues();
       values.put(Downloads.Impl.COLUMN_STATUS, Downloads.Impl.STATUS_RUNNING);
       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
@@ -1356,6 +1388,9 @@ public class DownloadManager {
                case Downloads.Impl.STATUS_QUEUED_FOR_WIFI:
                    return PAUSED_QUEUED_FOR_WIFI;

                case Downloads.Impl.STATUS_PAUSED_BY_USER:
                    return PAUSED_BY_USER;

                default:
                    return PAUSED_UNKNOWN;
            }
@@ -1411,6 +1446,7 @@ public class DownloadManager {
                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_BY_USER:
                    return STATUS_PAUSED;

                case Downloads.Impl.STATUS_SUCCESS:
+5 −0
Original line number Diff line number Diff line
@@ -592,6 +592,11 @@ public final class Downloads {
         */
        public static final int STATUS_QUEUED_FOR_WIFI = 196;

        /**
         * This download has been paused by user.
         */
        public static final int STATUS_PAUSED_BY_USER = 197;

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