summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/DownloadInfo.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/providers/downloads/DownloadInfo.java')
-rw-r--r--src/com/android/providers/downloads/DownloadInfo.java140
1 files changed, 69 insertions, 71 deletions
diff --git a/src/com/android/providers/downloads/DownloadInfo.java b/src/com/android/providers/downloads/DownloadInfo.java
index a2048958..3327e80b 100644
--- a/src/com/android/providers/downloads/DownloadInfo.java
+++ b/src/com/android/providers/downloads/DownloadInfo.java
@@ -175,9 +175,9 @@ public class DownloadInfo {
public static final int NETWORK_OK = 1;
/**
- * The network is unusuable for some unspecified reason.
+ * There is no network connectivity.
*/
- public static final int NETWORK_UNUSABLE_GENERIC = 2;
+ public static final int NETWORK_NO_CONNECTION = 2;
/**
* The download exceeds the maximum size for this network.
@@ -191,6 +191,16 @@ public class DownloadInfo {
public static final int NETWORK_RECOMMENDED_UNUSABLE_DUE_TO_SIZE = 4;
/**
+ * The current connection is roaming, and the download can't proceed over a roaming connection.
+ */
+ public static final int NETWORK_CANNOT_USE_ROAMING = 5;
+
+ /**
+ * The app requesting the download specific that it can't use the current network connection.
+ */
+ public static final int NETWORK_TYPE_DISALLOWED_BY_REQUESTOR = 6;
+
+ /**
* For intents used to notify the user that a download exceeds a size threshold, if this extra
* is true, WiFi is required for this download size; otherwise, it is only recommended.
*/
@@ -227,7 +237,6 @@ public class DownloadInfo {
public String mTitle;
public String mDescription;
public int mBypassRecommendedSizeLimit;
- public String mPausedReason;
public int mFuzz;
@@ -275,10 +284,12 @@ public class DownloadInfo {
}
/**
- * Returns the time when a download should be restarted. Must only
- * be called when numFailed > 0.
+ * Returns the time when a download should be restarted.
*/
- public long restartTime() {
+ public long restartTime(long now) {
+ if (mNumFailed == 0) {
+ return now;
+ }
if (mRetryAfter > 0) {
return mLastMod + mRetryAfter;
}
@@ -291,67 +302,29 @@ public class DownloadInfo {
* Returns whether this download (which the download manager hasn't seen yet)
* should be started.
*/
- public boolean isReadyToStart(long now) {
+ private boolean isReadyToStart(long now) {
+ if (mHasActiveThread) {
+ // already running
+ return false;
+ }
if (mControl == Downloads.Impl.CONTROL_PAUSED) {
// the download is paused, so it's not going to start
return false;
}
- if (mStatus == 0) {
- // status hasn't been initialized yet, this is a new download
- return true;
- }
- if (mStatus == Downloads.Impl.STATUS_PENDING) {
- // download is explicit marked as ready to start
- return true;
- }
- if (mStatus == Downloads.Impl.STATUS_RUNNING) {
- // download was interrupted (process killed, loss of power) while it was running,
- // without a chance to update the database
- return true;
- }
- if (mStatus == Downloads.Impl.STATUS_RUNNING_PAUSED) {
- if (mNumFailed == 0) {
- // download is waiting for network connectivity to return before it can resume
+ switch (mStatus) {
+ case 0: // status hasn't been initialized yet, this is a new download
+ case Downloads.Impl.STATUS_PENDING: // download is explicit marked as ready to start
+ case Downloads.Impl.STATUS_RUNNING: // download interrupted (process killed etc) while
+ // running, without a chance to update the database
return true;
- }
- if (restartTime() < now) {
- // download was waiting for a delayed restart, and the delay has expired
- return true;
- }
- }
- return false;
- }
- /**
- * Returns whether this download (which the download manager has already seen
- * and therefore potentially started) should be restarted.
- *
- * In a nutshell, this returns true if the download isn't already running
- * but should be, and it can know whether the download is already running
- * by checking the status.
- */
- public boolean isReadyToRestart(long now) {
- if (mControl == Downloads.Impl.CONTROL_PAUSED) {
- // the download is paused, so it's not going to restart
- return false;
- }
- if (mStatus == 0) {
- // download hadn't been initialized yet
- return true;
- }
- if (mStatus == Downloads.Impl.STATUS_PENDING) {
- // download is explicit marked as ready to start
- return true;
- }
- if (mStatus == Downloads.Impl.STATUS_RUNNING_PAUSED) {
- if (mNumFailed == 0) {
- // download is waiting for network connectivity to return before it can resume
+ case Downloads.Impl.STATUS_WAITING_FOR_NETWORK:
+ case Downloads.Impl.STATUS_QUEUED_FOR_WIFI:
return checkCanUseNetwork() == NETWORK_OK;
- }
- if (restartTime() < now) {
- // download was waiting for a delayed restart, and the delay has expired
- return true;
- }
+
+ case Downloads.Impl.STATUS_WAITING_TO_RETRY:
+ // download was waiting for a delayed restart
+ return restartTime(now) <= now;
}
return false;
}
@@ -377,10 +350,10 @@ public class DownloadInfo {
public int checkCanUseNetwork() {
Integer networkType = mSystemFacade.getActiveNetworkType();
if (networkType == null) {
- return NETWORK_UNUSABLE_GENERIC;
+ return NETWORK_NO_CONNECTION;
}
if (!isRoamingAllowed() && mSystemFacade.isNetworkRoaming()) {
- return NETWORK_UNUSABLE_GENERIC;
+ return NETWORK_CANNOT_USE_ROAMING;
}
return checkIsNetworkTypeAllowed(networkType);
}
@@ -394,6 +367,32 @@ public class DownloadInfo {
}
/**
+ * @return a non-localized string appropriate for logging corresponding to one of the
+ * NETWORK_* constants.
+ */
+ public String getLogMessageForNetworkError(int networkError) {
+ switch (networkError) {
+ case NETWORK_RECOMMENDED_UNUSABLE_DUE_TO_SIZE:
+ return "download size exceeds recommended limit for mobile network";
+
+ case NETWORK_UNUSABLE_DUE_TO_SIZE:
+ return "download size exceeds limit for mobile network";
+
+ case NETWORK_NO_CONNECTION:
+ return "no network connection available";
+
+ case NETWORK_CANNOT_USE_ROAMING:
+ return "download cannot use the current network connection because it is roaming";
+
+ case NETWORK_TYPE_DISALLOWED_BY_REQUESTOR:
+ return "download was requested to not use the current network type";
+
+ default:
+ return "unknown error with network connectivity";
+ }
+ }
+
+ /**
* Check if this download can proceed over the given network type.
* @param networkType a constant from ConnectivityManager.TYPE_*.
* @return one of the NETWORK_* constants
@@ -402,7 +401,7 @@ public class DownloadInfo {
if (mIsPublicApi) {
int flag = translateNetworkTypeToApiFlag(networkType);
if ((flag & mAllowedNetworkTypes) == 0) {
- return NETWORK_UNUSABLE_GENERIC;
+ return NETWORK_TYPE_DISALLOWED_BY_REQUESTOR;
}
}
return checkSizeAllowedForNetwork(networkType);
@@ -450,7 +449,11 @@ public class DownloadInfo {
return NETWORK_OK;
}
- void start(long now) {
+ void startIfReady(long now) {
+ if (!isReadyToStart(now)) {
+ return;
+ }
+
if (Constants.LOGV) {
Log.v(Constants.TAG, "Service spawning thread to handle download " + mId);
}
@@ -521,13 +524,10 @@ public class DownloadInfo {
if (Downloads.Impl.isStatusCompleted(mStatus)) {
return -1;
}
- if (mStatus != Downloads.Impl.STATUS_RUNNING_PAUSED) {
- return 0;
- }
- if (mNumFailed == 0) {
+ if (mStatus != Downloads.Impl.STATUS_WAITING_TO_RETRY) {
return 0;
}
- long when = restartTime();
+ long when = restartTime(now);
if (when <= now) {
return 0;
}
@@ -545,8 +545,6 @@ public class DownloadInfo {
}
void notifyPauseDueToSize(boolean isWifiRequired) {
- mPausedReason = mContext.getResources().getString(
- R.string.notification_need_wifi_for_size);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(getAllDownloadsUri());
intent.setClassName(SizeLimitActivity.class.getPackage().getName(),