frameworks/base
Revision | 2ab5749cf679ea7d26dd925e9a5a0a2bdb950d3d (tree) |
---|---|
Zeit | 2016-10-04 14:33:39 |
Autor | qqzhou <qqzhou@code...> |
Commiter | Zhao Wei Liew |
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
@@ -280,6 +280,13 @@ public class DownloadManager { | ||
280 | 280 | */ |
281 | 281 | public final static int PAUSED_UNKNOWN = 4; |
282 | 282 | |
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 | + | |
283 | 290 | /** |
284 | 291 | * Broadcast intent action sent by the download manager when a download completes. |
285 | 292 | */ |
@@ -922,6 +929,7 @@ public class DownloadManager { | ||
922 | 929 | parts.add(statusClause("=", Downloads.Impl.STATUS_WAITING_TO_RETRY)); |
923 | 930 | parts.add(statusClause("=", Downloads.Impl.STATUS_WAITING_FOR_NETWORK)); |
924 | 931 | parts.add(statusClause("=", Downloads.Impl.STATUS_QUEUED_FOR_WIFI)); |
932 | + parts.add(statusClause("=", Downloads.Impl.STATUS_PAUSED_MANUAL)); | |
925 | 933 | } |
926 | 934 | if ((mStatusFlags & STATUS_SUCCESSFUL) != 0) { |
927 | 935 | parts.add(statusClause("=", Downloads.Impl.STATUS_SUCCESS)); |
@@ -1173,6 +1181,34 @@ public class DownloadManager { | ||
1173 | 1181 | } |
1174 | 1182 | |
1175 | 1183 | /** |
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 | + /** | |
1176 | 1212 | * Returns maximum size, in bytes, of downloads that may go over a mobile connection; or null if |
1177 | 1213 | * there's no limit |
1178 | 1214 | * |
@@ -1546,6 +1582,9 @@ public class DownloadManager { | ||
1546 | 1582 | case Downloads.Impl.STATUS_QUEUED_FOR_WIFI: |
1547 | 1583 | return PAUSED_QUEUED_FOR_WIFI; |
1548 | 1584 | |
1585 | + case Downloads.Impl.STATUS_PAUSED_MANUAL: | |
1586 | + return PAUSED_MANUAL; | |
1587 | + | |
1549 | 1588 | default: |
1550 | 1589 | return PAUSED_UNKNOWN; |
1551 | 1590 | } |
@@ -1601,6 +1640,7 @@ public class DownloadManager { | ||
1601 | 1640 | case Downloads.Impl.STATUS_WAITING_TO_RETRY: |
1602 | 1641 | case Downloads.Impl.STATUS_WAITING_FOR_NETWORK: |
1603 | 1642 | case Downloads.Impl.STATUS_QUEUED_FOR_WIFI: |
1643 | + case Downloads.Impl.STATUS_PAUSED_MANUAL: | |
1604 | 1644 | return STATUS_PAUSED; |
1605 | 1645 | |
1606 | 1646 | case Downloads.Impl.STATUS_SUCCESS: |
@@ -598,6 +598,11 @@ public final class Downloads { | ||
598 | 598 | public static final int STATUS_QUEUED_FOR_WIFI = 196; |
599 | 599 | |
600 | 600 | /** |
601 | + * This download is paused manually. | |
602 | + */ | |
603 | + public static final int STATUS_PAUSED_MANUAL = 197; | |
604 | + | |
605 | + /** | |
601 | 606 | * This download couldn't be completed due to insufficient storage |
602 | 607 | * space. Typically, this is because the SD card is full. |
603 | 608 | */ |