Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 792e0910 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

DownloadManager and metered networks.

API to control whether a download is allowed to use metered networks.

Bug: 3001465
Change-Id: I29153d2a7495a2e9f76ef5be0a77696a85823839
parent 9f7cbf0e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3251,6 +3251,7 @@ package android.app {
    method public android.app.DownloadManager.Request addRequestHeader(java.lang.String, java.lang.String);
    method public void allowScanningByMediaScanner();
    method public android.app.DownloadManager.Request setAllowedNetworkTypes(int);
    method public android.app.DownloadManager.Request setAllowedOverMetered(boolean);
    method public android.app.DownloadManager.Request setAllowedOverRoaming(boolean);
    method public android.app.DownloadManager.Request setDescription(java.lang.CharSequence);
    method public android.app.DownloadManager.Request setDestinationInExternalFilesDir(android.content.Context, java.lang.String, java.lang.String);
+18 −2
Original line number Diff line number Diff line
@@ -349,6 +349,7 @@ public class DownloadManager {
        private String mMimeType;
        private boolean mRoamingAllowed = true;
        private int mAllowedNetworkTypes = ~0; // default to all network types allowed
        private boolean mAllowedOverMetered = true;
        private boolean mIsVisibleInDownloadsUi = true;
        private boolean mScannable = false;
        private boolean mUseSystemCache = false;
@@ -609,8 +610,11 @@ public class DownloadManager {
        }

        /**
         * Restrict the types of networks over which this download may proceed.  By default, all
         * network types are allowed.
         * Restrict the types of networks over which this download may proceed.
         * By default, all network types are allowed. Consider using
         * {@link #setAllowedOverMetered(boolean)} instead, since it's more
         * flexible.
         *
         * @param flags any combination of the NETWORK_* bit flags.
         * @return this object
         */
@@ -619,6 +623,17 @@ public class DownloadManager {
            return this;
        }

        /**
         * Set whether this download may proceed over a metered network
         * connection. By default, metered networks are allowed.
         *
         * @see ConnectivityManager#isActiveNetworkMetered()
         */
        public Request setAllowedOverMetered(boolean allow) {
            mAllowedOverMetered = allow;
            return this;
        }

        /**
         * Set whether this download may proceed over a roaming connection.  By default, roaming is
         * allowed.
@@ -672,6 +687,7 @@ public class DownloadManager {
            putIfNonNull(values, Downloads.Impl.COLUMN_DESCRIPTION, mDescription);
            putIfNonNull(values, Downloads.Impl.COLUMN_MIME_TYPE, mMimeType);

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