From 90fb15a7e52b1208b8d4f7518a61efb99580b5b0 Mon Sep 17 00:00:00 2001 From: Steve Howard Date: Thu, 9 Sep 2010 16:13:41 -0700 Subject: Support UI visibility and restarting in download manager. First, this change adds a column to the downloads table specifying whether a download should be displayed in the system downloads UI. It adds a public method to set this parameter when requesting a download, and a hidden method to filter queries based on this paramter (such filtering could be made public later, but it's not strictly necessary right now). Second, this change adds support for restarting a completed/failed download as a hidden method on DownloadManager. Currently it only works from the download manager's process - it'll be used by the new download manager UI. Change-Id: I15eda1a6e3717d1ce947a810b25ad3540cce809e --- api/current.xml | 13 ++++++ core/java/android/net/DownloadManager.java | 64 +++++++++++++++++++++++++++++- core/java/android/provider/Downloads.java | 8 ++++ 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/api/current.xml b/api/current.xml index dd83d81..977eeb6 100644 --- a/api/current.xml +++ b/api/current.xml @@ -96627,6 +96627,19 @@ + + + + selectionParts = new ArrayList(); if (mId != null) { uri = Uri.withAppendedPath(uri, mId.toString()); @@ -536,9 +563,14 @@ public class DownloadManager { parts.add("(" + statusClause(">=", 400) + " AND " + statusClause("<", 600) + ")"); } - selection = joinStrings(" OR ", parts); + selectionParts.add(joinStrings(" OR ", parts)); } + if (mOnlyIncludeVisibleInDownloadsUi) { + selectionParts.add(Downloads.Impl.COLUMN_IS_VISIBLE_IN_DOWNLOADS_UI + " != '0'"); + } + + String selection = joinStrings(" AND ", selectionParts); String orderDirection = (mOrderDirection == ORDER_ASCENDING ? "ASC" : "DESC"); String orderBy = mOrderByColumn + " " + orderDirection; @@ -628,6 +660,34 @@ public class DownloadManager { } /** + * Restart the given download, which must have already completed (successfully or not). This + * method will only work when called from within the download manager's process. + * @param id the ID of the download + * @hide + */ + public void restartDownload(long id) { + Cursor cursor = query(new Query().setFilterById(id)); + try { + if (!cursor.moveToFirst()) { + throw new IllegalArgumentException("No download with id " + id); + } + int status = cursor.getInt(cursor.getColumnIndex(COLUMN_STATUS)); + if (status != STATUS_SUCCESSFUL && status != STATUS_FAILED) { + throw new IllegalArgumentException("Cannot restart incomplete download: " + id); + } + } finally { + cursor.close(); + } + + ContentValues values = new ContentValues(); + values.put(Downloads.Impl.COLUMN_CURRENT_BYTES, 0); + values.put(Downloads.Impl.COLUMN_TOTAL_BYTES, -1); + values.putNull(Downloads.Impl._DATA); + values.put(Downloads.Impl.COLUMN_STATUS, Downloads.Impl.STATUS_PENDING); + mResolver.update(getDownloadUri(id), values, null, null); + } + + /** * Get the DownloadProvider URI for the download with the given ID. */ private Uri getDownloadUri(long id) { diff --git a/core/java/android/provider/Downloads.java b/core/java/android/provider/Downloads.java index 6bf0d5b..603e598 100644 --- a/core/java/android/provider/Downloads.java +++ b/core/java/android/provider/Downloads.java @@ -880,6 +880,14 @@ public final class Downloads { */ public static final String COLUMN_ALLOWED_NETWORK_TYPES = "allowed_network_types"; + /** + * Whether or not this download should be displayed in the system's Downloads UI. Defaults + * to true. + *

Type: INTEGER

+ *

Owner can Init/Read

+ */ + public static final String COLUMN_IS_VISIBLE_IN_DOWNLOADS_UI = "is_visible_in_downloads_ui"; + /* * Lists the destinations that an application can specify for a download. */ -- cgit v1.1