• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

frameworks/base


Commit MetaInfo

Revision2ab5749cf679ea7d26dd925e9a5a0a2bdb950d3d (tree)
Zeit2016-10-04 14:33:39
Autorqqzhou <qqzhou@code...>
CommiterZhao Wei Liew

Log Message

Download: Add support to manually pause/resume download

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

Ändern Zusammenfassung

Diff

--- a/core/java/android/app/DownloadManager.java
+++ b/core/java/android/app/DownloadManager.java
@@ -280,6 +280,13 @@ public class DownloadManager {
280280 */
281281 public final static int PAUSED_UNKNOWN = 4;
282282
283+ /**
284+ * Value of {@link #COLUMN_REASON} when the download is paused manually.
285+ *
286+ * @hide
287+ */
288+ public final static int PAUSED_MANUAL = 5;
289+
283290 /**
284291 * Broadcast intent action sent by the download manager when a download completes.
285292 */
@@ -922,6 +929,7 @@ public class DownloadManager {
922929 parts.add(statusClause("=", Downloads.Impl.STATUS_WAITING_TO_RETRY));
923930 parts.add(statusClause("=", Downloads.Impl.STATUS_WAITING_FOR_NETWORK));
924931 parts.add(statusClause("=", Downloads.Impl.STATUS_QUEUED_FOR_WIFI));
932+ parts.add(statusClause("=", Downloads.Impl.STATUS_PAUSED_MANUAL));
925933 }
926934 if ((mStatusFlags & STATUS_SUCCESSFUL) != 0) {
927935 parts.add(statusClause("=", Downloads.Impl.STATUS_SUCCESS));
@@ -1173,6 +1181,34 @@ public class DownloadManager {
11731181 }
11741182
11751183 /**
1184+ * Pause the given running download manually.
1185+ *
1186+ * @param id the ID of the download to be paused
1187+ * @return the number of downloads actually updated
1188+ * @hide
1189+ */
1190+ public int pauseDownload(long id) {
1191+ ContentValues values = new ContentValues();
1192+ values.put(Downloads.Impl.COLUMN_STATUS, Downloads.Impl.STATUS_PAUSED_MANUAL);
1193+
1194+ return mResolver.update(ContentUris.withAppendedId(mBaseUri, id), values, null, null);
1195+ }
1196+
1197+ /**
1198+ * Resume the given paused download manually.
1199+ *
1200+ * @param id the ID of the download to be resumed
1201+ * @return the number of downloads actually updated
1202+ * @hide
1203+ */
1204+ public int resumeDownload(long id) {
1205+ ContentValues values = new ContentValues();
1206+ values.put(Downloads.Impl.COLUMN_STATUS, Downloads.Impl.STATUS_RUNNING);
1207+
1208+ return mResolver.update(ContentUris.withAppendedId(mBaseUri, id), values, null, null);
1209+ }
1210+
1211+ /**
11761212 * Returns maximum size, in bytes, of downloads that may go over a mobile connection; or null if
11771213 * there's no limit
11781214 *
@@ -1546,6 +1582,9 @@ public class DownloadManager {
15461582 case Downloads.Impl.STATUS_QUEUED_FOR_WIFI:
15471583 return PAUSED_QUEUED_FOR_WIFI;
15481584
1585+ case Downloads.Impl.STATUS_PAUSED_MANUAL:
1586+ return PAUSED_MANUAL;
1587+
15491588 default:
15501589 return PAUSED_UNKNOWN;
15511590 }
@@ -1601,6 +1640,7 @@ public class DownloadManager {
16011640 case Downloads.Impl.STATUS_WAITING_TO_RETRY:
16021641 case Downloads.Impl.STATUS_WAITING_FOR_NETWORK:
16031642 case Downloads.Impl.STATUS_QUEUED_FOR_WIFI:
1643+ case Downloads.Impl.STATUS_PAUSED_MANUAL:
16041644 return STATUS_PAUSED;
16051645
16061646 case Downloads.Impl.STATUS_SUCCESS:
--- a/core/java/android/provider/Downloads.java
+++ b/core/java/android/provider/Downloads.java
@@ -598,6 +598,11 @@ public final class Downloads {
598598 public static final int STATUS_QUEUED_FOR_WIFI = 196;
599599
600600 /**
601+ * This download is paused manually.
602+ */
603+ public static final int STATUS_PAUSED_MANUAL = 197;
604+
605+ /**
601606 * This download couldn't be completed due to insufficient storage
602607 * space. Typically, this is because the SD card is full.
603608 */