diff options
Diffstat (limited to 'src/com/android/providers/downloads/DownloadThread.java')
-rw-r--r-- | src/com/android/providers/downloads/DownloadThread.java | 120 |
1 files changed, 60 insertions, 60 deletions
diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java index 2e7ab1dd..2709c4f5 100644 --- a/src/com/android/providers/downloads/DownloadThread.java +++ b/src/com/android/providers/downloads/DownloadThread.java @@ -81,7 +81,7 @@ public class DownloadThread extends Thread { public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); - int finalStatus = Downloads.STATUS_UNKNOWN_ERROR; + int finalStatus = Downloads.Impl.STATUS_UNKNOWN_ERROR; boolean countRetry = false; int retryAfter = 0; int redirectCount = mInfo.mRedirectCount; @@ -92,7 +92,7 @@ public class DownloadThread extends Thread { FileOutputStream stream = null; AndroidHttpClient client = null; PowerManager.WakeLock wakeLock = null; - Uri contentUri = Uri.parse(Downloads.CONTENT_URI + "/" + mInfo.mId); + Uri contentUri = Uri.parse(Downloads.Impl.CONTENT_URI + "/" + mInfo.mId); try { boolean continuingDownload = false; @@ -114,7 +114,7 @@ public class DownloadThread extends Thread { filename = mInfo.mFileName; if (filename != null) { if (!Helpers.isFilenameValid(filename)) { - finalStatus = Downloads.STATUS_FILE_ERROR; + finalStatus = Downloads.Impl.STATUS_FILE_ERROR; notifyDownloadCompleted( finalStatus, false, 0, 0, false, filename, null, mInfo.mMimeType); return; @@ -134,7 +134,7 @@ public class DownloadThread extends Thread { "can't resume interrupted non-resumable download"); } f.delete(); - finalStatus = Downloads.STATUS_PRECONDITION_FAILED; + finalStatus = Downloads.Impl.STATUS_PRECONDITION_FAILED; notifyDownloadCompleted( finalStatus, false, 0, 0, false, filename, null, mInfo.mMimeType); return; @@ -158,7 +158,7 @@ public class DownloadThread extends Thread { client = AndroidHttpClient.newInstance(userAgent()); - if (stream != null && mInfo.mDestination == Downloads.DESTINATION_EXTERNAL + if (stream != null && mInfo.mDestination == Downloads.Impl.DESTINATION_EXTERNAL && !DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING .equalsIgnoreCase(mimeType)) { try { @@ -211,7 +211,7 @@ http_request_loop: Log.d(Constants.TAG, "Arg exception trying to execute request for " + mInfo.mId + " : " + ex); } - finalStatus = Downloads.STATUS_BAD_REQUEST; + finalStatus = Downloads.Impl.STATUS_BAD_REQUEST; request.abort(); break http_request_loop; } catch (IOException ex) { @@ -223,9 +223,9 @@ http_request_loop: } } if (!Helpers.isNetworkAvailable(mContext)) { - finalStatus = Downloads.STATUS_RUNNING_PAUSED; + finalStatus = Downloads.Impl.STATUS_RUNNING_PAUSED; } else if (mInfo.mNumFailed < Constants.MAX_RETRIES) { - finalStatus = Downloads.STATUS_RUNNING_PAUSED; + finalStatus = Downloads.Impl.STATUS_RUNNING_PAUSED; countRetry = true; } else { if (Constants.LOGV) { @@ -235,7 +235,7 @@ http_request_loop: Log.d(Constants.TAG, "IOException trying to execute request for " + mInfo.mId + " : " + ex); } - finalStatus = Downloads.STATUS_HTTP_DATA_ERROR; + finalStatus = Downloads.Impl.STATUS_HTTP_DATA_ERROR; } request.abort(); break http_request_loop; @@ -246,7 +246,7 @@ http_request_loop: if (Constants.LOGVV) { Log.v(Constants.TAG, "got HTTP response code 503"); } - finalStatus = Downloads.STATUS_RUNNING_PAUSED; + finalStatus = Downloads.Impl.STATUS_RUNNING_PAUSED; countRetry = true; Header header = response.getFirstHeader("Retry-After"); if (header != null) { @@ -287,7 +287,7 @@ http_request_loop: } else if (Config.LOGD) { Log.d(Constants.TAG, "too many redirects for download " + mInfo.mId); } - finalStatus = Downloads.STATUS_TOO_MANY_REDIRECTS; + finalStatus = Downloads.Impl.STATUS_TOO_MANY_REDIRECTS; request.abort(); break http_request_loop; } @@ -312,17 +312,17 @@ http_request_loop: "Couldn't resolve redirect URI for download " + mInfo.mId); } - finalStatus = Downloads.STATUS_BAD_REQUEST; + finalStatus = Downloads.Impl.STATUS_BAD_REQUEST; request.abort(); break http_request_loop; } ++redirectCount; - finalStatus = Downloads.STATUS_RUNNING_PAUSED; + finalStatus = Downloads.Impl.STATUS_RUNNING_PAUSED; request.abort(); break http_request_loop; } } - if ((!continuingDownload && statusCode != Downloads.STATUS_SUCCESS) + if ((!continuingDownload && statusCode != Downloads.Impl.STATUS_SUCCESS) || (continuingDownload && statusCode != 206)) { if (Constants.LOGV) { Log.d(Constants.TAG, "http error " + statusCode + " for " + mInfo.mUri); @@ -330,14 +330,14 @@ http_request_loop: Log.d(Constants.TAG, "http error " + statusCode + " for download " + mInfo.mId); } - if (Downloads.isStatusError(statusCode)) { + if (Downloads.Impl.isStatusError(statusCode)) { finalStatus = statusCode; } else if (statusCode >= 300 && statusCode < 400) { - finalStatus = Downloads.STATUS_UNHANDLED_REDIRECT; - } else if (continuingDownload && statusCode == Downloads.STATUS_SUCCESS) { - finalStatus = Downloads.STATUS_PRECONDITION_FAILED; + finalStatus = Downloads.Impl.STATUS_UNHANDLED_REDIRECT; + } else if (continuingDownload && statusCode == Downloads.Impl.STATUS_SUCCESS) { + finalStatus = Downloads.Impl.STATUS_PRECONDITION_FAILED; } else { - finalStatus = Downloads.STATUS_UNHANDLED_HTTP_CODE; + finalStatus = Downloads.Impl.STATUS_UNHANDLED_HTTP_CODE; } request.abort(); break http_request_loop; @@ -404,7 +404,7 @@ http_request_loop: if (Config.LOGD) { Log.d(Constants.TAG, "can't know size of download, giving up"); } - finalStatus = Downloads.STATUS_LENGTH_REQUIRED; + finalStatus = Downloads.Impl.STATUS_LENGTH_REQUIRED; request.abort(); break http_request_loop; } @@ -431,18 +431,18 @@ http_request_loop: } ContentValues values = new ContentValues(); - values.put(Downloads._DATA, filename); + values.put(Downloads.Impl._DATA, filename); if (headerETag != null) { values.put(Constants.ETAG, headerETag); } if (mimeType != null) { - values.put(Downloads.COLUMN_MIME_TYPE, mimeType); + values.put(Downloads.Impl.COLUMN_MIME_TYPE, mimeType); } int contentLength = -1; if (headerContentLength != null) { contentLength = Integer.parseInt(headerContentLength); } - values.put(Downloads.COLUMN_TOTAL_BYTES, contentLength); + values.put(Downloads.Impl.COLUMN_TOTAL_BYTES, contentLength); mContext.getContentResolver().update(contentUri, values, null, null); } @@ -458,9 +458,9 @@ http_request_loop: } } if (!Helpers.isNetworkAvailable(mContext)) { - finalStatus = Downloads.STATUS_RUNNING_PAUSED; + finalStatus = Downloads.Impl.STATUS_RUNNING_PAUSED; } else if (mInfo.mNumFailed < Constants.MAX_RETRIES) { - finalStatus = Downloads.STATUS_RUNNING_PAUSED; + finalStatus = Downloads.Impl.STATUS_RUNNING_PAUSED; countRetry = true; } else { if (Constants.LOGV) { @@ -473,7 +473,7 @@ http_request_loop: Log.d(Constants.TAG, "IOException getting entity for download " + mInfo.mId + " : " + ex); } - finalStatus = Downloads.STATUS_HTTP_DATA_ERROR; + finalStatus = Downloads.Impl.STATUS_HTTP_DATA_ERROR; } request.abort(); break http_request_loop; @@ -491,7 +491,7 @@ http_request_loop: } } ContentValues values = new ContentValues(); - values.put(Downloads.COLUMN_CURRENT_BYTES, bytesSoFar); + values.put(Downloads.Impl.COLUMN_CURRENT_BYTES, bytesSoFar); mContext.getContentResolver().update(contentUri, values, null, null); if (!mInfo.mNoIntegrity && headerETag == null) { if (Constants.LOGV) { @@ -505,11 +505,11 @@ http_request_loop: Log.d(Constants.TAG, "can't resume interrupted download with no ETag"); } - finalStatus = Downloads.STATUS_PRECONDITION_FAILED; + finalStatus = Downloads.Impl.STATUS_PRECONDITION_FAILED; } else if (!Helpers.isNetworkAvailable(mContext)) { - finalStatus = Downloads.STATUS_RUNNING_PAUSED; + finalStatus = Downloads.Impl.STATUS_RUNNING_PAUSED; } else if (mInfo.mNumFailed < Constants.MAX_RETRIES) { - finalStatus = Downloads.STATUS_RUNNING_PAUSED; + finalStatus = Downloads.Impl.STATUS_RUNNING_PAUSED; countRetry = true; } else { if (Constants.LOGV) { @@ -519,16 +519,16 @@ http_request_loop: Log.d(Constants.TAG, "download IOException for download " + mInfo.mId + " : " + ex); } - finalStatus = Downloads.STATUS_HTTP_DATA_ERROR; + finalStatus = Downloads.Impl.STATUS_HTTP_DATA_ERROR; } request.abort(); break http_request_loop; } if (bytesRead == -1) { // success ContentValues values = new ContentValues(); - values.put(Downloads.COLUMN_CURRENT_BYTES, bytesSoFar); + values.put(Downloads.Impl.COLUMN_CURRENT_BYTES, bytesSoFar); if (headerContentLength == null) { - values.put(Downloads.COLUMN_TOTAL_BYTES, bytesSoFar); + values.put(Downloads.Impl.COLUMN_TOTAL_BYTES, bytesSoFar); } mContext.getContentResolver().update(contentUri, values, null, null); if ((headerContentLength != null) @@ -542,11 +542,11 @@ http_request_loop: Log.d(Constants.TAG, "mismatched content length for " + mInfo.mId); } - finalStatus = Downloads.STATUS_LENGTH_REQUIRED; + finalStatus = Downloads.Impl.STATUS_LENGTH_REQUIRED; } else if (!Helpers.isNetworkAvailable(mContext)) { - finalStatus = Downloads.STATUS_RUNNING_PAUSED; + finalStatus = Downloads.Impl.STATUS_RUNNING_PAUSED; } else if (mInfo.mNumFailed < Constants.MAX_RETRIES) { - finalStatus = Downloads.STATUS_RUNNING_PAUSED; + finalStatus = Downloads.Impl.STATUS_RUNNING_PAUSED; countRetry = true; } else { if (Constants.LOGV) { @@ -555,7 +555,7 @@ http_request_loop: Log.d(Constants.TAG, "closed socket for download " + mInfo.mId); } - finalStatus = Downloads.STATUS_HTTP_DATA_ERROR; + finalStatus = Downloads.Impl.STATUS_HTTP_DATA_ERROR; } break http_request_loop; } @@ -568,7 +568,7 @@ http_request_loop: stream = new FileOutputStream(filename, true); } stream.write(data, 0, bytesRead); - if (mInfo.mDestination == Downloads.DESTINATION_EXTERNAL + if (mInfo.mDestination == Downloads.Impl.DESTINATION_EXTERNAL && !DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING .equalsIgnoreCase(mimeType)) { try { @@ -587,7 +587,7 @@ http_request_loop: } catch (IOException ex) { if (!Helpers.discardPurgeableFiles( mContext, Constants.BUFFER_SIZE)) { - finalStatus = Downloads.STATUS_FILE_ERROR; + finalStatus = Downloads.Impl.STATUS_FILE_ERROR; break http_request_loop; } } @@ -598,7 +598,7 @@ http_request_loop: && now - timeLastNotification > Constants.MIN_PROGRESS_TIME) { ContentValues values = new ContentValues(); - values.put(Downloads.COLUMN_CURRENT_BYTES, bytesSoFar); + values.put(Downloads.Impl.COLUMN_CURRENT_BYTES, bytesSoFar); mContext.getContentResolver().update( contentUri, values, null, null); bytesNotified = bytesSoFar; @@ -609,29 +609,29 @@ http_request_loop: Log.v(Constants.TAG, "downloaded " + bytesSoFar + " for " + mInfo.mUri); } synchronized (mInfo) { - if (mInfo.mControl == Downloads.CONTROL_PAUSED) { + if (mInfo.mControl == Downloads.Impl.CONTROL_PAUSED) { if (Constants.LOGV) { Log.v(Constants.TAG, "paused " + mInfo.mUri); } - finalStatus = Downloads.STATUS_RUNNING_PAUSED; + finalStatus = Downloads.Impl.STATUS_RUNNING_PAUSED; request.abort(); break http_request_loop; } } - if (mInfo.mStatus == Downloads.STATUS_CANCELED) { + if (mInfo.mStatus == Downloads.Impl.STATUS_CANCELED) { if (Constants.LOGV) { Log.d(Constants.TAG, "canceled " + mInfo.mUri); } else if (Config.LOGD) { // Log.d(Constants.TAG, "canceled id " + mInfo.mId); } - finalStatus = Downloads.STATUS_CANCELED; + finalStatus = Downloads.Impl.STATUS_CANCELED; break http_request_loop; } } if (Constants.LOGV) { Log.v(Constants.TAG, "download completed for " + mInfo.mUri); } - finalStatus = Downloads.STATUS_SUCCESS; + finalStatus = Downloads.Impl.STATUS_SUCCESS; } break; } @@ -639,7 +639,7 @@ http_request_loop: if (Config.LOGD) { Log.d(Constants.TAG, "FileNotFoundException for " + filename + " : " + ex); } - finalStatus = Downloads.STATUS_FILE_ERROR; + finalStatus = Downloads.Impl.STATUS_FILE_ERROR; // falls through to the code that reports an error } catch (RuntimeException ex) { //sometimes the socket code throws unchecked exceptions if (Constants.LOGV) { @@ -647,7 +647,7 @@ http_request_loop: } else if (Config.LOGD) { Log.d(Constants.TAG, "Exception for id " + mInfo.mId, ex); } - finalStatus = Downloads.STATUS_UNKNOWN_ERROR; + finalStatus = Downloads.Impl.STATUS_UNKNOWN_ERROR; // falls through to the code that reports an error } finally { mInfo.mHasActiveThread = false; @@ -672,10 +672,10 @@ http_request_loop: } if (filename != null) { // if the download wasn't successful, delete the file - if (Downloads.isStatusError(finalStatus)) { + if (Downloads.Impl.isStatusError(finalStatus)) { new File(filename).delete(); filename = null; - } else if (Downloads.isStatusSuccess(finalStatus) && + } else if (Downloads.Impl.isStatusSuccess(finalStatus) && DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING .equalsIgnoreCase(mimeType)) { // transfer the file to the DRM content provider @@ -683,14 +683,14 @@ http_request_loop: Intent item = DrmStore.addDrmFile(mContext.getContentResolver(), file, null); if (item == null) { Log.w(Constants.TAG, "unable to add file " + filename + " to DrmProvider"); - finalStatus = Downloads.STATUS_UNKNOWN_ERROR; + finalStatus = Downloads.Impl.STATUS_UNKNOWN_ERROR; } else { filename = item.getDataString(); mimeType = item.getType(); } file.delete(); - } else if (Downloads.isStatusSuccess(finalStatus)) { + } else if (Downloads.Impl.isStatusSuccess(finalStatus)) { // make sure the file is readable FileUtils.setPermissions(filename, 0644, -1, -1); @@ -721,7 +721,7 @@ http_request_loop: String filename, String uri, String mimeType) { notifyThroughDatabase( status, countRetry, retryAfter, redirectCount, gotData, filename, uri, mimeType); - if (Downloads.isStatusCompleted(status)) { + if (Downloads.Impl.isStatusCompleted(status)) { notifyThroughIntent(); } } @@ -730,13 +730,13 @@ http_request_loop: int status, boolean countRetry, int retryAfter, int redirectCount, boolean gotData, String filename, String uri, String mimeType) { ContentValues values = new ContentValues(); - values.put(Downloads.COLUMN_STATUS, status); - values.put(Downloads._DATA, filename); + values.put(Downloads.Impl.COLUMN_STATUS, status); + values.put(Downloads.Impl._DATA, filename); if (uri != null) { - values.put(Downloads.COLUMN_URI, uri); + values.put(Downloads.Impl.COLUMN_URI, uri); } - values.put(Downloads.COLUMN_MIME_TYPE, mimeType); - values.put(Downloads.COLUMN_LAST_MODIFICATION, System.currentTimeMillis()); + values.put(Downloads.Impl.COLUMN_MIME_TYPE, mimeType); + values.put(Downloads.Impl.COLUMN_LAST_MODIFICATION, System.currentTimeMillis()); values.put(Constants.RETRY_AFTER_X_REDIRECT_COUNT, retryAfter + (redirectCount << 28)); if (!countRetry) { values.put(Constants.FAILED_CONNECTIONS, 0); @@ -746,8 +746,8 @@ http_request_loop: values.put(Constants.FAILED_CONNECTIONS, mInfo.mNumFailed + 1); } - mContext.getContentResolver().update( - ContentUris.withAppendedId(Downloads.CONTENT_URI, mInfo.mId), values, null, null); + mContext.getContentResolver().update(ContentUris.withAppendedId( + Downloads.Impl.CONTENT_URI, mInfo.mId), values, null, null); } /** @@ -755,7 +755,7 @@ http_request_loop: * download completed even if it's not actively watching the cursor. */ private void notifyThroughIntent() { - Uri uri = Uri.parse(Downloads.CONTENT_URI + "/" + mInfo.mId); + Uri uri = Uri.parse(Downloads.Impl.CONTENT_URI + "/" + mInfo.mId); mInfo.sendIntentIfRequested(uri, mContext); } |