diff options
Diffstat (limited to 'src/com/android/providers/downloads')
3 files changed, 25 insertions, 26 deletions
diff --git a/src/com/android/providers/downloads/DownloadInfo.java b/src/com/android/providers/downloads/DownloadInfo.java index 36816b59..7b291683 100644 --- a/src/com/android/providers/downloads/DownloadInfo.java +++ b/src/com/android/providers/downloads/DownloadInfo.java @@ -73,7 +73,6 @@ public class DownloadInfo { info.mNumFailed = getInt(Constants.FAILED_CONNECTIONS); int retryRedirect = getInt(Constants.RETRY_AFTER_X_REDIRECT_COUNT); info.mRetryAfter = retryRedirect & 0xfffffff; - info.mRedirectCount = retryRedirect >> 28; info.mLastMod = getLong(Downloads.Impl.COLUMN_LAST_MODIFICATION); info.mPackage = getString(info.mPackage, Downloads.Impl.COLUMN_NOTIFICATION_PACKAGE); info.mClass = getString(info.mClass, Downloads.Impl.COLUMN_NOTIFICATION_CLASS); @@ -223,7 +222,6 @@ public class DownloadInfo { public int mStatus; public int mNumFailed; public int mRetryAfter; - public int mRedirectCount; public long mLastMod; public String mPackage; public String mClass; @@ -506,7 +504,6 @@ public class DownloadInfo { Log.v(Constants.TAG, "STATUS : " + mStatus); Log.v(Constants.TAG, "FAILED_C: " + mNumFailed); Log.v(Constants.TAG, "RETRY_AF: " + mRetryAfter); - Log.v(Constants.TAG, "REDIRECT: " + mRedirectCount); Log.v(Constants.TAG, "LAST_MOD: " + mLastMod); Log.v(Constants.TAG, "PACKAGE : " + mPackage); Log.v(Constants.TAG, "CLASS : " + mClass); diff --git a/src/com/android/providers/downloads/DownloadService.java b/src/com/android/providers/downloads/DownloadService.java index 2d87b80e..76a317d1 100644 --- a/src/com/android/providers/downloads/DownloadService.java +++ b/src/com/android/providers/downloads/DownloadService.java @@ -363,7 +363,7 @@ public class DownloadService extends Service { if (info.shouldScanFile()) { // initiate rescan of the file to - which will populate // mediaProviderUri column in this row - if (!scanFile(info, true, false)) { + if (!scanFile(info, false, true)) { throw new IllegalStateException("scanFile failed!"); } } else { @@ -377,9 +377,9 @@ public class DownloadService extends Service { // in DownProvider database (the order of deletion is important). getContentResolver().delete(Uri.parse(info.mMediaProviderUri), null, null); - getContentResolver().delete(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, - Downloads.Impl._ID + " = ? ", - new String[]{String.valueOf(info.mId)}); + // the following deletes the file and then deletes it from downloads db + Helpers.deleteFile(getContentResolver(), info.mId, info.mFileName, + info.mMimeType); } } } @@ -580,21 +580,23 @@ public class DownloadService extends Service { mMediaScannerService.requestScanFile(info.mFileName, info.mMimeType, new IMediaScannerListener.Stub() { public void scanCompleted(String path, Uri uri) { - if (uri != null && updateDatabase) { - // file is scanned and mediaprovider returned uri. store it in downloads - // table (i.e., update this downloaded file's row) + if (updateDatabase) { + // Mark this as 'scanned' in the database + // so that it is NOT subject to re-scanning by MediaScanner + // next time this database row is encountered ContentValues values = new ContentValues(); values.put(Constants.MEDIA_SCANNED, 1); - values.put(Downloads.Impl.COLUMN_MEDIAPROVIDER_URI, - uri.toString()); + if (uri != null) { + values.put(Downloads.Impl.COLUMN_MEDIAPROVIDER_URI, + uri.toString()); + } getContentResolver().update(key, values, null, null); - } else if (uri == null && deleteFile) { - // callback returned NO uri..that means this file doesn't - // exist in MediaProvider. but it still needs to be deleted - // TODO don't scan files that are not scannable by MediaScanner. - // create a public method in MediaFile.java to return false - // if the given file's mimetype is not any of the types - // the mediaprovider is interested in. + } else if (deleteFile) { + if (uri != null) { + // use the Uri returned to delete it from the MediaProvider + getContentResolver().delete(uri, null, null); + } + // delete the file and delete its row from the downloads db Helpers.deleteFile(resolver, id, path, mimeType); } } diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java index 2995bfb6..461d8cea 100644 --- a/src/com/android/providers/downloads/DownloadThread.java +++ b/src/com/android/providers/downloads/DownloadThread.java @@ -26,6 +26,7 @@ import android.os.PowerManager; import android.os.Process; import android.provider.Downloads; import android.provider.DrmStore; +import android.text.TextUtils; import android.util.Log; import android.util.Pair; @@ -87,7 +88,6 @@ public class DownloadThread extends Thread { public State(DownloadInfo info) { mMimeType = sanitizeMimeType(info.mMimeType); - mRedirectCount = info.mRedirectCount; mRequestUri = info.mUri; mFilename = info.mFileName; } @@ -199,7 +199,7 @@ public class DownloadThread extends Thread { } cleanupDestination(state, finalStatus); notifyDownloadCompleted(finalStatus, state.mCountRetry, state.mRetryAfter, - state.mRedirectCount, state.mGotData, state.mFilename, + state.mGotData, state.mFilename, state.mNewUri, state.mMimeType); mInfo.mHasActiveThread = false; } @@ -790,7 +790,7 @@ public class DownloadThread extends Thread { */ private void setupDestinationFile(State state, InnerState innerState) throws StopRequest { - if (state.mFilename != null) { // only true if we've already run a thread for this download + if (!TextUtils.isEmpty(state.mFilename)) { // only true if we've already run a thread for this download if (!Helpers.isFilenameValid(state.mFilename)) { // this should never happen throw new StopRequest(Downloads.Impl.STATUS_FILE_ERROR, @@ -853,17 +853,17 @@ public class DownloadThread extends Thread { * Stores information about the completed download, and notifies the initiating application. */ private void notifyDownloadCompleted( - int status, boolean countRetry, int retryAfter, int redirectCount, boolean gotData, + int status, boolean countRetry, int retryAfter, boolean gotData, String filename, String uri, String mimeType) { notifyThroughDatabase( - status, countRetry, retryAfter, redirectCount, gotData, filename, uri, mimeType); + status, countRetry, retryAfter, gotData, filename, uri, mimeType); if (Downloads.Impl.isStatusCompleted(status)) { mInfo.sendIntentIfRequested(); } } private void notifyThroughDatabase( - int status, boolean countRetry, int retryAfter, int redirectCount, boolean gotData, + int status, boolean countRetry, int retryAfter, boolean gotData, String filename, String uri, String mimeType) { ContentValues values = new ContentValues(); values.put(Downloads.Impl.COLUMN_STATUS, status); @@ -873,7 +873,7 @@ public class DownloadThread extends Thread { } values.put(Downloads.Impl.COLUMN_MIME_TYPE, mimeType); values.put(Downloads.Impl.COLUMN_LAST_MODIFICATION, mSystemFacade.currentTimeMillis()); - values.put(Constants.RETRY_AFTER_X_REDIRECT_COUNT, retryAfter + (redirectCount << 28)); + values.put(Constants.RETRY_AFTER_X_REDIRECT_COUNT, retryAfter); if (!countRetry) { values.put(Constants.FAILED_CONNECTIONS, 0); } else if (gotData) { |