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

Commit edb4e6a7 authored by qqzhou's avatar qqzhou Committed by Francis Guevarra
Browse files

Download: add to support pause/resume download by manual

We add pause and resume API here so that application can
pause and resume downloads manually by DownloadManager.
This contains two points:
1. add pause and resume download APIs.
2. add another paused reason for this download status.

Change-Id: I606b48ca20f43bcc6c119683818c2ab6ff03bfe5
parent d264d831
Loading
Loading
Loading
Loading
+40 −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 manual.
    *
    * @hide
    */
    public final static int PAUSED_BY_MANUAL = 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_MANUAL));
                }
                if ((mStatusFlags & STATUS_SUCCESSFUL) != 0) {
                    parts.add(statusClause("=", Downloads.Impl.STATUS_SUCCESS));
@@ -1099,6 +1107,34 @@ public class DownloadManager {
        mResolver.update(mBaseUri, values, getWhereClauseForIds(ids), getWhereArgsForIds(ids));
    }

    /**
     * Pause the given running download by manual.
     *
     * @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_BY_MANUAL);

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

    /**
     * Resume the given paused download by manual.
     *
     * @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
@@ -1335,6 +1371,9 @@ public class DownloadManager {
                case Downloads.Impl.STATUS_QUEUED_FOR_WIFI:
                    return PAUSED_QUEUED_FOR_WIFI;

                case Downloads.Impl.STATUS_PAUSED_BY_MANUAL:
                    return PAUSED_BY_MANUAL;

                default:
                    return PAUSED_UNKNOWN;
            }
@@ -1390,6 +1429,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_MANUAL:
                    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 is paused by manual.
         */
        public static final int STATUS_PAUSED_BY_MANUAL = 197;

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