diff options
-rw-r--r-- | res/drawable/download_error.xml | 11 | ||||
-rw-r--r-- | src/com/android/providers/downloads/DownloadNotifier.java | 33 |
2 files changed, 43 insertions, 1 deletions
diff --git a/res/drawable/download_error.xml b/res/drawable/download_error.xml new file mode 100644 index 00000000..8e79df00 --- /dev/null +++ b/res/drawable/download_error.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8"?> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + + <path + android:fillColor="#fafafa" + android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-2h2v2zM13,13h-2L11,7h2v6z"/> +</vector> diff --git a/src/com/android/providers/downloads/DownloadNotifier.java b/src/com/android/providers/downloads/DownloadNotifier.java index 5e1b9de2..7fbb35b8 100644 --- a/src/com/android/providers/downloads/DownloadNotifier.java +++ b/src/com/android/providers/downloads/DownloadNotifier.java @@ -166,10 +166,22 @@ public class DownloadNotifier { } } + // Check error status about downloads. If error exists, will + // update icon and content title/content text in notification. + boolean hasErrorStatus = false; + for (DownloadInfo info : cluster) { + if (isErrorStatus(info.mStatus)) { + hasErrorStatus = true; + break; + } + } + // Show relevant icon if (type == TYPE_ACTIVE) { if (hasPausedStatus) { builder.setSmallIcon(R.drawable.download_pause); + } else if (hasErrorStatus) { + builder.setSmallIcon(R.drawable.download_error); } else { builder.setSmallIcon(android.R.drawable.stat_sys_download); } @@ -223,9 +235,9 @@ public class DownloadNotifier { String remainingText = null; String percentText = null; String speedAsSizeText = null; + long total = 0; if (type == TYPE_ACTIVE) { long current = 0; - long total = 0; long speed = 0; synchronized (mDownloadSpeed) { for (DownloadInfo info : cluster) { @@ -289,6 +301,11 @@ public class DownloadNotifier { } else if (speedAsSizeText != null) { builder.setContentText(res.getString(R.string.download_speed_text, remainingText, speedAsSizeText)); + } else if (hasErrorStatus) { + builder.setContentText(res.getText( + R.string.notification_download_failed)); + if (total == 0) + builder.setProgress(100, 0, false); } builder.setContentInfo(percentText); @@ -317,6 +334,11 @@ public class DownloadNotifier { if (type == TYPE_ACTIVE) { if (hasPausedStatus) { builder.setContentTitle(res.getString(R.string.download_queued)); + } else if (hasErrorStatus) { + builder.setContentText(res.getText( + R.string.notification_download_failed)); + if (total == 0) + builder.setProgress(100, 0, false); } else { builder.setContentTitle(res.getQuantityString( R.plurals.notif_summary_active, cluster.size(), cluster.size())); @@ -421,4 +443,13 @@ public class DownloadNotifier { return status == Downloads.Impl.STATUS_WAITING_FOR_NETWORK || status == Downloads.Impl.STATUS_PAUSED_BY_MANUAL; } + + private static boolean isErrorStatus(int status) { + boolean isErrorStatus = Downloads.Impl.isStatusError(status) + || Downloads.Impl.isStatusClientError(status) + || Downloads.Impl.isStatusServerError(status) + || status == Downloads.Impl.STATUS_INSUFFICIENT_SPACE_ERROR + || status == Downloads.Impl.STATUS_DEVICE_NOT_FOUND_ERROR; + return isErrorStatus; + } } |