diff options
6 files changed, 28 insertions, 5 deletions
diff --git a/src/com/android/providers/downloads/DownloadInfo.java b/src/com/android/providers/downloads/DownloadInfo.java index 1e670e12..28adfbdf 100644 --- a/src/com/android/providers/downloads/DownloadInfo.java +++ b/src/com/android/providers/downloads/DownloadInfo.java @@ -92,6 +92,7 @@ public class DownloadInfo { info.mIsPublicApi = getInt(Downloads.Impl.COLUMN_IS_PUBLIC_API) != 0; info.mAllowedNetworkTypes = getInt(Downloads.Impl.COLUMN_ALLOWED_NETWORK_TYPES); info.mAllowRoaming = getInt(Downloads.Impl.COLUMN_ALLOW_ROAMING) != 0; + info.mAllowMetered = getInt(Downloads.Impl.COLUMN_ALLOW_METERED) != 0; info.mTitle = getString(Downloads.Impl.COLUMN_TITLE); info.mDescription = getString(Downloads.Impl.COLUMN_DESCRIPTION); info.mBypassRecommendedSizeLimit = @@ -221,6 +222,7 @@ public class DownloadInfo { public boolean mIsPublicApi; public int mAllowedNetworkTypes; public boolean mAllowRoaming; + public boolean mAllowMetered; public String mTitle; public String mDescription; public int mBypassRecommendedSizeLimit; @@ -352,6 +354,9 @@ public class DownloadInfo { if (!isRoamingAllowed() && mSystemFacade.isNetworkRoaming()) { return NETWORK_CANNOT_USE_ROAMING; } + if (!mAllowMetered && mSystemFacade.isActiveNetworkMetered()) { + return NETWORK_TYPE_DISALLOWED_BY_REQUESTOR; + } return checkIsNetworkTypeAllowed(info.getType()); } @@ -518,6 +523,7 @@ public class DownloadInfo { pw.printPair("mAllowedNetworkTypes", mAllowedNetworkTypes); pw.printPair("mAllowRoaming", mAllowRoaming); + pw.printPair("mAllowMetered", mAllowMetered); pw.println(); pw.decreaseIndent(); diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java index 4a3844f9..5fbe42a5 100644 --- a/src/com/android/providers/downloads/DownloadProvider.java +++ b/src/com/android/providers/downloads/DownloadProvider.java @@ -63,7 +63,7 @@ public final class DownloadProvider extends ContentProvider { /** Database filename */ private static final String DB_NAME = "downloads.db"; /** Current database version */ - private static final int DB_VERSION = 107; + private static final int DB_VERSION = 108; /** Name of table in the database */ private static final String DB_TABLE = "downloads"; @@ -308,6 +308,11 @@ public final class DownloadProvider extends ContentProvider { addColumn(db, DB_TABLE, Downloads.Impl.COLUMN_ERROR_MSG, "TEXT"); break; + case 108: + addColumn(db, DB_TABLE, Downloads.Impl.COLUMN_ALLOW_METERED, + "INTEGER NOT NULL DEFAULT 1"); + break; + default: throw new IllegalStateException("Don't know how to upgrade to " + version); } @@ -632,6 +637,7 @@ public final class DownloadProvider extends ContentProvider { if (isPublicApi) { copyInteger(Downloads.Impl.COLUMN_ALLOWED_NETWORK_TYPES, values, filteredValues); copyBoolean(Downloads.Impl.COLUMN_ALLOW_ROAMING, values, filteredValues); + copyBoolean(Downloads.Impl.COLUMN_ALLOW_METERED, values, filteredValues); } if (Constants.LOGVV) { @@ -767,6 +773,7 @@ public final class DownloadProvider extends ContentProvider { values.remove(Downloads.Impl.COLUMN_NOTIFICATION_PACKAGE); // checked later in insert() values.remove(Downloads.Impl.COLUMN_ALLOWED_NETWORK_TYPES); values.remove(Downloads.Impl.COLUMN_ALLOW_ROAMING); + values.remove(Downloads.Impl.COLUMN_ALLOW_METERED); values.remove(Downloads.Impl.COLUMN_IS_VISIBLE_IN_DOWNLOADS_UI); values.remove(Downloads.Impl.COLUMN_MEDIA_SCANNED); Iterator<Map.Entry<String, Object>> iterator = values.valueSet().iterator(); diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java index 7108cec3..4de5134b 100644 --- a/src/com/android/providers/downloads/DownloadThread.java +++ b/src/com/android/providers/downloads/DownloadThread.java @@ -270,8 +270,6 @@ public class DownloadThread extends Thread { } else if (networkUsable == DownloadInfo.NETWORK_RECOMMENDED_UNUSABLE_DUE_TO_SIZE) { status = Downloads.Impl.STATUS_QUEUED_FOR_WIFI; mInfo.notifyPauseDueToSize(false); - } else if (networkUsable == DownloadInfo.NETWORK_BLOCKED) { - status = Downloads.Impl.STATUS_BLOCKED; } throw new StopRequestException(status, mInfo.getLogMessageForNetworkError(networkUsable)); @@ -806,8 +804,6 @@ public class DownloadThread extends Thread { case DownloadInfo.NETWORK_UNUSABLE_DUE_TO_SIZE: case DownloadInfo.NETWORK_RECOMMENDED_UNUSABLE_DUE_TO_SIZE: return Downloads.Impl.STATUS_QUEUED_FOR_WIFI; - case DownloadInfo.NETWORK_BLOCKED: - return Downloads.Impl.STATUS_BLOCKED; default: return Downloads.Impl.STATUS_WAITING_FOR_NETWORK; } diff --git a/src/com/android/providers/downloads/RealSystemFacade.java b/src/com/android/providers/downloads/RealSystemFacade.java index f2423d47..6580f909 100644 --- a/src/com/android/providers/downloads/RealSystemFacade.java +++ b/src/com/android/providers/downloads/RealSystemFacade.java @@ -42,6 +42,12 @@ class RealSystemFacade implements SystemFacade { return activeInfo; } + @Override + public boolean isActiveNetworkMetered() { + final ConnectivityManager conn = ConnectivityManager.from(mContext); + return conn.isActiveNetworkMetered(); + } + public boolean isNetworkRoaming() { ConnectivityManager connectivity = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); diff --git a/src/com/android/providers/downloads/SystemFacade.java b/src/com/android/providers/downloads/SystemFacade.java index a1e4098c..d1439354 100644 --- a/src/com/android/providers/downloads/SystemFacade.java +++ b/src/com/android/providers/downloads/SystemFacade.java @@ -19,6 +19,8 @@ interface SystemFacade { */ public NetworkInfo getActiveNetworkInfo(int uid); + public boolean isActiveNetworkMetered(); + /** * @see android.telephony.TelephonyManager#isNetworkRoaming */ diff --git a/tests/src/com/android/providers/downloads/FakeSystemFacade.java b/tests/src/com/android/providers/downloads/FakeSystemFacade.java index fbaf6366..c184de83 100644 --- a/tests/src/com/android/providers/downloads/FakeSystemFacade.java +++ b/tests/src/com/android/providers/downloads/FakeSystemFacade.java @@ -18,6 +18,7 @@ public class FakeSystemFacade implements SystemFacade { long mTimeMillis = 0; Integer mActiveNetworkType = ConnectivityManager.TYPE_WIFI; boolean mIsRoaming = false; + boolean mIsMetered = false; Long mMaxBytesOverMobile = null; Long mRecommendedMaxBytesOverMobile = null; List<Intent> mBroadcastsSent = new ArrayList<Intent>(); @@ -45,6 +46,11 @@ public class FakeSystemFacade implements SystemFacade { } } + @Override + public boolean isActiveNetworkMetered() { + return mIsMetered; + } + public boolean isNetworkRoaming() { return mIsRoaming; } |