Fix large file download failure issue
Catherine Liu [Tue, 5 Feb 2013 22:00:50 +0000 (16:00 -0600)]
The root cause is int overflow as integer can only hold size
Integer.MAX_VALUE = 0x7FFFFFFF. It is about 2G. So, when a file size
is greater than 2G, it throws a "NumberFormatException", and then
mark this download "unsuccessfully".
The progress bar in notification for the large file downloading was
not correct either. The total file size was converted from long to
int value when in builder.setProgress().

Change-Id: Ib038860e26cf8cade2c423403585c207f8b8979b

src/com/android/providers/downloads/DownloadNotification.java
src/com/android/providers/downloads/DownloadThread.java

index bbd39f6..efdc08b 100644 (file)
@@ -190,8 +190,13 @@ class DownloadNotification {
             if (hasPausedText) {
                 builder.setContentText(item.mPausedText);
             } else {
-                builder.setProgress(
-                        (int) item.mTotalTotal, (int) item.mTotalCurrent, item.mTotalTotal == -1);
+                long max = item.mTotalTotal;
+                long progress = item.mTotalCurrent;
+                while(max > Integer.MAX_VALUE) {
+                    max = max / 1024;
+                    progress = progress / 1024;
+                }
+                builder.setProgress((int) max, (int) progress, item.mTotalTotal == -1);
                 if (hasContentText) {
                     builder.setContentInfo(
                             buildPercentageLabel(mContext, item.mTotalTotal, item.mTotalCurrent));
index bd91eaa..537a9ea 100644 (file)
@@ -473,7 +473,7 @@ public class DownloadThread extends Thread {
         mContext.getContentResolver().update(mInfo.getAllDownloadsUri(), values, null, null);
 
         boolean lengthMismatched = (innerState.mHeaderContentLength != null)
-                && (state.mCurrentBytes != Integer.parseInt(innerState.mHeaderContentLength));
+                && (state.mCurrentBytes != Long.parseLong(innerState.mHeaderContentLength));
         if (lengthMismatched) {
             if (cannotResume(state)) {
                 throw new StopRequestException(Downloads.Impl.STATUS_CANNOT_RESUME,