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
This commit is contained in:
@@ -96627,6 +96627,19 @@
|
|||||||
<parameter name="title" type="java.lang.String">
|
<parameter name="title" type="java.lang.String">
|
||||||
</parameter>
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="setVisibleInDownloadsUi"
|
||||||
|
return="android.net.DownloadManager.Request"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<parameter name="isVisible" type="boolean">
|
||||||
|
</parameter>
|
||||||
|
</method>
|
||||||
<field name="NETWORK_MOBILE"
|
<field name="NETWORK_MOBILE"
|
||||||
type="int"
|
type="int"
|
||||||
transient="false"
|
transient="false"
|
||||||
|
|||||||
@@ -276,6 +276,7 @@ public class DownloadManager {
|
|||||||
private String mMediaType;
|
private String mMediaType;
|
||||||
private boolean mRoamingAllowed = true;
|
private boolean mRoamingAllowed = true;
|
||||||
private int mAllowedNetworkTypes = ~0; // default to all network types allowed
|
private int mAllowedNetworkTypes = ~0; // default to all network types allowed
|
||||||
|
private boolean mIsVisibleInDownloadsUi = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param uri the HTTP URI to download.
|
* @param uri the HTTP URI to download.
|
||||||
@@ -386,6 +387,17 @@ public class DownloadManager {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether this download should be displayed in the system's Downloads UI. True by
|
||||||
|
* default.
|
||||||
|
* @param isVisible whether to display this download in the Downloads UI
|
||||||
|
* @return this object
|
||||||
|
*/
|
||||||
|
public Request setVisibleInDownloadsUi(boolean isVisible) {
|
||||||
|
mIsVisibleInDownloadsUi = isVisible;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ContentValues to be passed to DownloadProvider.insert()
|
* @return ContentValues to be passed to DownloadProvider.insert()
|
||||||
*/
|
*/
|
||||||
@@ -418,6 +430,7 @@ public class DownloadManager {
|
|||||||
|
|
||||||
values.put(Downloads.Impl.COLUMN_ALLOWED_NETWORK_TYPES, mAllowedNetworkTypes);
|
values.put(Downloads.Impl.COLUMN_ALLOWED_NETWORK_TYPES, mAllowedNetworkTypes);
|
||||||
values.put(Downloads.Impl.COLUMN_ALLOW_ROAMING, mRoamingAllowed);
|
values.put(Downloads.Impl.COLUMN_ALLOW_ROAMING, mRoamingAllowed);
|
||||||
|
values.put(Downloads.Impl.COLUMN_IS_VISIBLE_IN_DOWNLOADS_UI, mIsVisibleInDownloadsUi);
|
||||||
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
@@ -458,6 +471,7 @@ public class DownloadManager {
|
|||||||
private Integer mStatusFlags = null;
|
private Integer mStatusFlags = null;
|
||||||
private String mOrderByColumn = Downloads.COLUMN_LAST_MODIFICATION;
|
private String mOrderByColumn = Downloads.COLUMN_LAST_MODIFICATION;
|
||||||
private int mOrderDirection = ORDER_DESCENDING;
|
private int mOrderDirection = ORDER_DESCENDING;
|
||||||
|
private boolean mOnlyIncludeVisibleInDownloadsUi = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Include only the download with the given ID.
|
* Include only the download with the given ID.
|
||||||
@@ -478,6 +492,19 @@ public class DownloadManager {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controls whether this query includes downloads not visible in the system's Downloads UI.
|
||||||
|
* @param value if true, this query will only include downloads that should be displayed in
|
||||||
|
* the system's Downloads UI; if false (the default), this query will include
|
||||||
|
* both visible and invisible downloads.
|
||||||
|
* @return this object
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public Query setOnlyIncludeVisibleInDownloadsUi(boolean value) {
|
||||||
|
mOnlyIncludeVisibleInDownloadsUi = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the sort order of the returned Cursor.
|
* Change the sort order of the returned Cursor.
|
||||||
*
|
*
|
||||||
@@ -511,7 +538,7 @@ public class DownloadManager {
|
|||||||
*/
|
*/
|
||||||
Cursor runQuery(ContentResolver resolver, String[] projection) {
|
Cursor runQuery(ContentResolver resolver, String[] projection) {
|
||||||
Uri uri = Downloads.CONTENT_URI;
|
Uri uri = Downloads.CONTENT_URI;
|
||||||
String selection = null;
|
List<String> selectionParts = new ArrayList<String>();
|
||||||
|
|
||||||
if (mId != null) {
|
if (mId != null) {
|
||||||
uri = Uri.withAppendedPath(uri, mId.toString());
|
uri = Uri.withAppendedPath(uri, mId.toString());
|
||||||
@@ -536,9 +563,14 @@ public class DownloadManager {
|
|||||||
parts.add("(" + statusClause(">=", 400)
|
parts.add("(" + statusClause(">=", 400)
|
||||||
+ " AND " + statusClause("<", 600) + ")");
|
+ " 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 orderDirection = (mOrderDirection == ORDER_ASCENDING ? "ASC" : "DESC");
|
||||||
String orderBy = mOrderByColumn + " " + orderDirection;
|
String orderBy = mOrderByColumn + " " + orderDirection;
|
||||||
|
|
||||||
@@ -627,6 +659,34 @@ public class DownloadManager {
|
|||||||
return mResolver.openFileDescriptor(getDownloadUri(id), "r");
|
return mResolver.openFileDescriptor(getDownloadUri(id), "r");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Get the DownloadProvider URI for the download with the given ID.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -880,6 +880,14 @@ public final class Downloads {
|
|||||||
*/
|
*/
|
||||||
public static final String COLUMN_ALLOWED_NETWORK_TYPES = "allowed_network_types";
|
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.
|
||||||
|
* <P>Type: INTEGER</P>
|
||||||
|
* <P>Owner can Init/Read</P>
|
||||||
|
*/
|
||||||
|
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.
|
* Lists the destinations that an application can specify for a download.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user