Skip to content

Commit c0e5b8c

Browse files
jsharkeyAndroid (Google) Code Review
authored andcommitted
Merge "DownloadManager and metered networks."
2 parents 455b7bb + 792e091 commit c0e5b8c

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3265,6 +3265,7 @@ package android.app {
32653265
method public android.app.DownloadManager.Request addRequestHeader(java.lang.String, java.lang.String);
32663266
method public void allowScanningByMediaScanner();
32673267
method public android.app.DownloadManager.Request setAllowedNetworkTypes(int);
3268+
method public android.app.DownloadManager.Request setAllowedOverMetered(boolean);
32683269
method public android.app.DownloadManager.Request setAllowedOverRoaming(boolean);
32693270
method public android.app.DownloadManager.Request setDescription(java.lang.CharSequence);
32703271
method public android.app.DownloadManager.Request setDestinationInExternalFilesDir(android.content.Context, java.lang.String, java.lang.String);

core/java/android/app/DownloadManager.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ public static class Request {
349349
private String mMimeType;
350350
private boolean mRoamingAllowed = true;
351351
private int mAllowedNetworkTypes = ~0; // default to all network types allowed
352+
private boolean mAllowedOverMetered = true;
352353
private boolean mIsVisibleInDownloadsUi = true;
353354
private boolean mScannable = false;
354355
private boolean mUseSystemCache = false;
@@ -609,8 +610,11 @@ public Request setNotificationVisibility(int visibility) {
609610
}
610611

611612
/**
612-
* Restrict the types of networks over which this download may proceed. By default, all
613-
* network types are allowed.
613+
* Restrict the types of networks over which this download may proceed.
614+
* By default, all network types are allowed. Consider using
615+
* {@link #setAllowedOverMetered(boolean)} instead, since it's more
616+
* flexible.
617+
*
614618
* @param flags any combination of the NETWORK_* bit flags.
615619
* @return this object
616620
*/
@@ -619,6 +623,17 @@ public Request setAllowedNetworkTypes(int flags) {
619623
return this;
620624
}
621625

626+
/**
627+
* Set whether this download may proceed over a metered network
628+
* connection. By default, metered networks are allowed.
629+
*
630+
* @see ConnectivityManager#isActiveNetworkMetered()
631+
*/
632+
public Request setAllowedOverMetered(boolean allow) {
633+
mAllowedOverMetered = allow;
634+
return this;
635+
}
636+
622637
/**
623638
* Set whether this download may proceed over a roaming connection. By default, roaming is
624639
* allowed.
@@ -672,6 +687,7 @@ ContentValues toContentValues(String packageName) {
672687
putIfNonNull(values, Downloads.Impl.COLUMN_DESCRIPTION, mDescription);
673688
putIfNonNull(values, Downloads.Impl.COLUMN_MIME_TYPE, mMimeType);
674689

690+
// TODO: add COLUMN_ALLOW_METERED and persist
675691
values.put(Downloads.Impl.COLUMN_VISIBILITY, mNotificationVisibility);
676692
values.put(Downloads.Impl.COLUMN_ALLOWED_NETWORK_TYPES, mAllowedNetworkTypes);
677693
values.put(Downloads.Impl.COLUMN_ALLOW_ROAMING, mRoamingAllowed);

0 commit comments

Comments
 (0)