summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/DownloadInfo.java
diff options
context:
space:
mode:
authorSteve Howard <showard@google.com>2010-09-30 18:18:51 -0700
committerSteve Howard <showard@google.com>2010-09-30 19:22:22 -0700
commit26604ffc248081b8014ff7260536d18b43cb0de9 (patch)
tree58c2d16bdfafd2865f91e6f1618d7599a9830bed /src/com/android/providers/downloads/DownloadInfo.java
parent8df47822435f7f66dd34f87dcaa73bbbcd808483 (diff)
downloadandroid_packages_providers_DownloadProvider-26604ffc248081b8014ff7260536d18b43cb0de9.tar.gz
android_packages_providers_DownloadProvider-26604ffc248081b8014ff7260536d18b43cb0de9.tar.bz2
android_packages_providers_DownloadProvider-26604ffc248081b8014ff7260536d18b43cb0de9.zip
Seriously improve error reporting in DownloadThread.
My old error reporting strategy for DownloadThread was to log the stack trace for the exception, so we'd know exactly what conditions caused the StopRequest. hackbod suggested that we shouldn't log tracebacks as they clutter the log. Instead, we should just always include a little string tag explaining why the request is being stopped -- this is more concise and more useful to developers. There are three main changes here to acheive this goal: * make StopRequest require a short, log-friendly error message upon construction, and add such a message to all construction sites * make a similar change to GenerateSaveFileError, so that the variety of errors that originate with Helpers.generateSaveFile() get similarly fine-grained and concise error reporting * make network usable checking code return a distinct error code for each distinct negative condition, and add a utility to return a log-friendly error message for each such code. Finally, I cleaned up some of the ways errors/exceptions are handled in the process. Change-Id: Ie70cbf3f2960e260e97f8449258e25218d0f900f
Diffstat (limited to 'src/com/android/providers/downloads/DownloadInfo.java')
-rw-r--r--src/com/android/providers/downloads/DownloadInfo.java46
1 files changed, 41 insertions, 5 deletions
diff --git a/src/com/android/providers/downloads/DownloadInfo.java b/src/com/android/providers/downloads/DownloadInfo.java
index b6f478c8..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.
*/
@@ -340,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);
}
@@ -357,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
@@ -365,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);