summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorSteve Howard <showard@google.com>2010-09-16 12:04:17 -0700
committerSteve Howard <showard@google.com>2010-09-20 13:45:30 -0700
commitb9a0ad7182209d4aca708e13e876e9b1b43ffafc (patch)
treee49d39e80dfc9c2ffc6a43c81f08ee0edce26c31 /ui
parentdbefa6f5eff88f97dd91a8adfd65dbd946adb99e (diff)
downloadandroid_packages_providers_DownloadProvider-b9a0ad7182209d4aca708e13e876e9b1b43ffafc.tar.gz
android_packages_providers_DownloadProvider-b9a0ad7182209d4aca708e13e876e9b1b43ffafc.tar.bz2
android_packages_providers_DownloadProvider-b9a0ad7182209d4aca708e13e876e9b1b43ffafc.zip
Improve file error reporting + new detailed error messages in UI
* support new error code for "destination file already exists" * improve error handling for various file error cases to return a more specific error code when appropriate * make UI support more detailed error messages for some cases * use Uri.getPath() instead of Uri.getSchemeSpecificPart() for file URIs Change-Id: Icb01d4d3b47c7776be3ddcd8347212e950cd023e
Diffstat (limited to 'ui')
-rw-r--r--ui/res/values/strings.xml19
-rw-r--r--ui/src/com/android/providers/downloads/ui/DownloadList.java63
2 files changed, 78 insertions, 4 deletions
diff --git a/ui/res/values/strings.xml b/ui/res/values/strings.xml
index 063ed04e..bb3654af 100644
--- a/ui/res/values/strings.xml
+++ b/ui/res/values/strings.xml
@@ -65,6 +65,25 @@
<!-- Text for dialog when user clicks on a completed download but the file is missing
[CHAR LIMIT=200] -->
<string name="dialog_file_missing_body">The downloaded file cannot be found.</string>
+ <!-- Text for dialog when user clicks on a download that failed due to insufficient space on
+ external storage [CHAR LIMIT=200] -->
+ <string name="dialog_insufficient_space_on_external">Cannot finish download. There is not
+ enough space on external storage.</string>
+ <!-- Text for dialog when user clicks on a download that failed due to insufficient space on
+ the internal download cache [CHAR LIMIT=200] -->
+ <string name="dialog_insufficient_space_on_cache">Cannot finish download. There is not enough
+ space on internal download storage.</string>
+ <!-- Text for dialog when user clicks on a download that failed because it was interrupted and
+ the server doesn't support resuming downloads [CHAR LIMIT=200] -->
+ <string name="dialog_cannot_resume">Download interrupted. It cannot be resumed.</string>
+ <!-- Text for dialog when user clicks on a download that failed because the requested
+ destination file already exists [CHAR LIMIT=200] -->
+ <string name="dialog_file_already_exists">Cannot download. The destination file already exists.
+ </string>
+ <!-- Text for dialog when user clicks on a download that failed because it was requested to go
+ on the external media, which is not mounted [CHAR LIMIT=200] -->
+ <string name="dialog_media_not_found">Cannot download. The external media is not available.
+ </string>
<!-- Text for a toast appearing when a user clicks on a completed download, informing the user
that there is no application on the device that can open the file that was downloaded
[CHAR LIMIT=200] -->
diff --git a/ui/src/com/android/providers/downloads/ui/DownloadList.java b/ui/src/com/android/providers/downloads/ui/DownloadList.java
index 71e17233..0cbffeb2 100644
--- a/ui/src/com/android/providers/downloads/ui/DownloadList.java
+++ b/ui/src/com/android/providers/downloads/ui/DownloadList.java
@@ -29,6 +29,7 @@ import android.database.Cursor;
import android.net.DownloadManager;
import android.net.Uri;
import android.os.Bundle;
+import android.os.Environment;
import android.os.Handler;
import android.provider.Downloads;
import android.util.Log;
@@ -80,6 +81,7 @@ public class DownloadList extends Activity
private int mIdColumnId;
private int mLocalUriColumnId;
private int mMediaTypeColumnId;
+ private int mErrorCodeColumndId;
private boolean mIsSortedBySize = false;
private Set<Long> mSelectedIds = new HashSet<Long>();
@@ -130,6 +132,8 @@ public class DownloadList extends Activity
mDateSortedCursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI);
mMediaTypeColumnId =
mDateSortedCursor.getColumnIndexOrThrow(DownloadManager.COLUMN_MEDIA_TYPE);
+ mErrorCodeColumndId =
+ mDateSortedCursor.getColumnIndexOrThrow(DownloadManager.COLUMN_ERROR_CODE);
mDateSortedAdapter = new DateSortedDownloadAdapter(this, mDateSortedCursor, this);
mDateOrderedListView.setAdapter(mDateSortedAdapter);
@@ -305,7 +309,8 @@ public class DownloadList extends Activity
getContentResolver().openFileDescriptor(localUri, "r").close();
} catch (FileNotFoundException exc) {
Log.d(LOG_TAG, "Failed to open download " + cursor.getLong(mIdColumnId), exc);
- showFailedDialog(cursor.getLong(mIdColumnId), R.string.dialog_file_missing_body);
+ showFailedDialog(cursor.getLong(mIdColumnId),
+ getString(R.string.dialog_file_missing_body));
return;
} catch (IOException exc) {
// close() failed, not a problem
@@ -345,15 +350,65 @@ public class DownloadList extends Activity
break;
case DownloadManager.STATUS_FAILED:
- showFailedDialog(id, R.string.dialog_failed_body);
+ showFailedDialog(id, getErrorMessage(cursor));
break;
}
}
- private void showFailedDialog(long downloadId, int dialogBodyResource) {
+ /**
+ * @return the appropriate error message for the failed download pointed to by cursor
+ */
+ private String getErrorMessage(Cursor cursor) {
+ switch (cursor.getInt(mErrorCodeColumndId)) {
+ case DownloadManager.ERROR_FILE_ALREADY_EXISTS:
+ if (isOnExternalStorage(cursor)) {
+ return getString(R.string.dialog_file_already_exists);
+ } else {
+ // the download manager should always find a free filename for cache downloads,
+ // so this indicates a strange internal error
+ return getUnknownErrorMessage();
+ }
+
+ case DownloadManager.ERROR_INSUFFICIENT_SPACE:
+ if (isOnExternalStorage(cursor)) {
+ return getString(R.string.dialog_insufficient_space_on_external);
+ } else {
+ return getString(R.string.dialog_insufficient_space_on_cache);
+ }
+
+ case DownloadManager.ERROR_DEVICE_NOT_FOUND:
+ return getString(R.string.dialog_media_not_found);
+
+ case DownloadManager.ERROR_CANNOT_RESUME:
+ return getString(R.string.dialog_cannot_resume);
+
+ default:
+ return getUnknownErrorMessage();
+ }
+ }
+
+ private boolean isOnExternalStorage(Cursor cursor) {
+ String localUriString = cursor.getString(mLocalUriColumnId);
+ if (localUriString == null) {
+ return false;
+ }
+ Uri localUri = Uri.parse(localUriString);
+ if (!localUri.getScheme().equals("file")) {
+ return false;
+ }
+ String path = localUri.getPath();
+ String externalRoot = Environment.getExternalStorageDirectory().getPath();
+ return path.startsWith(externalRoot);
+ }
+
+ private String getUnknownErrorMessage() {
+ return getString(R.string.dialog_failed_body);
+ }
+
+ private void showFailedDialog(long downloadId, String dialogBody) {
new AlertDialog.Builder(this)
.setTitle(R.string.dialog_title_not_available)
- .setMessage(getResources().getString(dialogBodyResource))
+ .setMessage(dialogBody)
.setPositiveButton(R.string.remove_download, getDeleteClickHandler(downloadId))
.setNegativeButton(R.string.retry_download, getRestartClickHandler(downloadId))
.show();