From c6f5aad265cfc36a64cd2bdb5adf3cc9736bbd80 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Queru Date: Tue, 20 Jan 2009 10:08:46 -0800 Subject: Match the official code style guide. This fixes a number of style violations that weren't caught by automated tools and brings those files closer to compliance with the official style guide for this language. --- src/com/android/providers/downloads/Constants.java | 2 +- .../providers/downloads/DownloadFileInfo.java | 16 +- .../android/providers/downloads/DownloadInfo.java | 150 ++++++------- .../providers/downloads/DownloadNotification.java | 62 +++--- .../providers/downloads/DownloadProvider.java | 5 +- .../providers/downloads/DownloadReceiver.java | 5 +- .../providers/downloads/DownloadService.java | 236 ++++++++++----------- .../providers/downloads/DownloadThread.java | 184 ++++++++-------- src/com/android/providers/downloads/Helpers.java | 8 +- 9 files changed, 341 insertions(+), 327 deletions(-) (limited to 'src') diff --git a/src/com/android/providers/downloads/Constants.java b/src/com/android/providers/downloads/Constants.java index cffda04a..c4da326a 100644 --- a/src/com/android/providers/downloads/Constants.java +++ b/src/com/android/providers/downloads/Constants.java @@ -29,7 +29,7 @@ public class Constants { public static final String TAG = "DownloadManager"; /** The column that used to be used for the HTTP method of the request */ - public static final String RETRY_AFTER___REDIRECT_COUNT = "method"; + public static final String RETRY_AFTER_X_REDIRECT_COUNT = "method"; /** The column that used to be used for the magic OTA update filename */ public static final String OTA_UPDATE = "otaupdate"; diff --git a/src/com/android/providers/downloads/DownloadFileInfo.java b/src/com/android/providers/downloads/DownloadFileInfo.java index 29cbd940..ce423880 100644 --- a/src/com/android/providers/downloads/DownloadFileInfo.java +++ b/src/com/android/providers/downloads/DownloadFileInfo.java @@ -22,13 +22,13 @@ import java.io.FileOutputStream; * Stores information about the file in which a download gets saved. */ public class DownloadFileInfo { - public DownloadFileInfo(String filename, FileOutputStream stream, int status) { - this.filename = filename; - this.stream = stream; - this.status = status; - } + String mFileName; + FileOutputStream mStream; + int mStatus; - String filename; - FileOutputStream stream; - int status; + public DownloadFileInfo(String fileName, FileOutputStream stream, int status) { + mFileName = fileName; + mStream = stream; + mStatus = status; + } } diff --git a/src/com/android/providers/downloads/DownloadInfo.java b/src/com/android/providers/downloads/DownloadInfo.java index e051f41a..24bdbfa3 100644 --- a/src/com/android/providers/downloads/DownloadInfo.java +++ b/src/com/android/providers/downloads/DownloadInfo.java @@ -16,81 +16,81 @@ package com.android.providers.downloads; -import android.net.Uri; import android.content.Context; import android.content.Intent; +import android.net.Uri; import android.provider.Downloads; /** * Stores information about an individual download. */ public class DownloadInfo { - public int id; - public String uri; - public boolean noIntegrity; - public String hint; - public String filename; - public String mimetype; - public int destination; - public int visibility; - public int control; - public int status; - public int numFailed; - public int retryAfter; - public int redirectCount; - public long lastMod; - public String pckg; - public String clazz; - public String extras; - public String cookies; - public String userAgent; - public String referer; - public int totalBytes; - public int currentBytes; - public String etag; - public boolean mediaScanned; + public int mId; + public String mUri; + public boolean mNoIntegrity; + public String mHint; + public String mFileName; + public String mMimeType; + public int mDestination; + public int mVisibility; + public int mControl; + public int mStatus; + public int mNumFailed; + public int mRetryAfter; + public int mRedirectCount; + public long mLastMod; + public String mPackage; + public String mClass; + public String mExtras; + public String mCookies; + public String mUserAgent; + public String mReferer; + public int mTotalBytes; + public int mCurrentBytes; + public String mETag; + public boolean mMediaScanned; - public volatile boolean hasActiveThread; + public volatile boolean mHasActiveThread; public DownloadInfo(int id, String uri, boolean noIntegrity, - String hint, String filename, - String mimetype, int destination, int visibility, int control, + String hint, String fileName, + String mimeType, int destination, int visibility, int control, int status, int numFailed, int retryAfter, int redirectCount, long lastMod, String pckg, String clazz, String extras, String cookies, - String userAgent, String referer, int totalBytes, int currentBytes, String etag, + String userAgent, String referer, int totalBytes, int currentBytes, String eTag, boolean mediaScanned) { - this.id = id; - this.uri = uri; - this.noIntegrity = noIntegrity; - this.hint = hint; - this.filename = filename; - this.mimetype = mimetype; - this.destination = destination; - this.visibility = visibility; - this.control = control; - this.status = status; - this.numFailed = numFailed; - this.retryAfter = retryAfter; - this.redirectCount = redirectCount; - this.lastMod = lastMod; - this.pckg = pckg; - this.clazz = clazz; - this.extras = extras; - this.cookies = cookies; - this.userAgent = userAgent; - this.referer = referer; - this.totalBytes = totalBytes; - this.currentBytes = currentBytes; - this.etag = etag; - this.mediaScanned = mediaScanned; + mId = id; + mUri = uri; + mNoIntegrity = noIntegrity; + mHint = hint; + mFileName = fileName; + mMimeType = mimeType; + mDestination = destination; + mVisibility = visibility; + mControl = control; + mStatus = status; + mNumFailed = numFailed; + mRetryAfter = retryAfter; + mRedirectCount = redirectCount; + mLastMod = lastMod; + mPackage = pckg; + mClass = clazz; + mExtras = extras; + mCookies = cookies; + mUserAgent = userAgent; + mReferer = referer; + mTotalBytes = totalBytes; + mCurrentBytes = currentBytes; + mETag = eTag; + mMediaScanned = mediaScanned; } public void sendIntentIfRequested(Uri contentUri, Context context) { - if (pckg != null && clazz != null) { + if (mPackage != null && mClass != null) { Intent intent = new Intent(Downloads.DOWNLOAD_COMPLETED_ACTION); - intent.setClassName(pckg, clazz); - if (extras != null) { - intent.putExtra(Downloads.NOTIFICATION_EXTRAS, extras); + intent.setClassName(mPackage, mClass); + if (mExtras != null) { + intent.putExtra(Downloads.NOTIFICATION_EXTRAS, mExtras); } // We only send the content: URI, for security reasons. Otherwise, malicious // applications would have an easier time spoofing download results by @@ -105,12 +105,12 @@ public class DownloadInfo { * be called when numFailed > 0. */ public long restartTime() { - if (retryAfter > 0) { - return lastMod + retryAfter; + if (mRetryAfter > 0) { + return mLastMod + mRetryAfter; } - return lastMod + + return mLastMod + Constants.RETRY_FIRST_DELAY * - (1000 + Helpers.rnd.nextInt(1001)) * (1 << (numFailed - 1)); + (1000 + Helpers.sRandom.nextInt(1001)) * (1 << (mNumFailed - 1)); } /** @@ -118,25 +118,25 @@ public class DownloadInfo { * should be started. */ public boolean isReadyToStart(long now) { - if (control == Downloads.CONTROL_PAUSED) { + if (mControl == Downloads.CONTROL_PAUSED) { // the download is paused, so it's not going to start return false; } - if (status == 0) { + if (mStatus == 0) { // status hasn't been initialized yet, this is a new download return true; } - if (status == Downloads.STATUS_PENDING) { + if (mStatus == Downloads.STATUS_PENDING) { // download is explicit marked as ready to start return true; } - if (status == Downloads.STATUS_RUNNING) { + if (mStatus == Downloads.STATUS_RUNNING) { // download was interrupted (process killed, loss of power) while it was running, // without a chance to update the database return true; } - if (status == Downloads.STATUS_RUNNING_PAUSED) { - if (numFailed == 0) { + if (mStatus == Downloads.STATUS_RUNNING_PAUSED) { + if (mNumFailed == 0) { // download is waiting for network connectivity to return before it can resume return true; } @@ -157,20 +157,20 @@ public class DownloadInfo { * by checking the status. */ public boolean isReadyToRestart(long now) { - if (control == Downloads.CONTROL_PAUSED) { + if (mControl == Downloads.CONTROL_PAUSED) { // the download is paused, so it's not going to restart return false; } - if (status == 0) { + if (mStatus == 0) { // download hadn't been initialized yet return true; } - if (status == Downloads.STATUS_PENDING) { + if (mStatus == Downloads.STATUS_PENDING) { // download is explicit marked as ready to start return true; } - if (status == Downloads.STATUS_RUNNING_PAUSED) { - if (numFailed == 0) { + if (mStatus == Downloads.STATUS_RUNNING_PAUSED) { + if (mNumFailed == 0) { // download is waiting for network connectivity to return before it can resume return true; } @@ -187,10 +187,10 @@ public class DownloadInfo { * completion. */ public boolean hasCompletionNotification() { - if (!Downloads.isStatusCompleted(status)) { + if (!Downloads.isStatusCompleted(mStatus)) { return false; } - if (visibility == Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) { + if (mVisibility == Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) { return true; } return false; @@ -203,7 +203,7 @@ public class DownloadInfo { if (!available) { return false; } - if (destination == Downloads.DESTINATION_CACHE_PARTITION_NOROAMING) { + if (mDestination == Downloads.DESTINATION_CACHE_PARTITION_NOROAMING) { return !roaming; } else { return true; diff --git a/src/com/android/providers/downloads/DownloadNotification.java b/src/com/android/providers/downloads/DownloadNotification.java index ed17ab7a..68373271 100644 --- a/src/com/android/providers/downloads/DownloadNotification.java +++ b/src/com/android/providers/downloads/DownloadNotification.java @@ -60,28 +60,28 @@ class DownloadNotification { * */ static class NotificationItem { - int id; // This first db _id for the download for the app - int totalCurrent = 0; - int totalTotal = 0; - int titleCount = 0; - String packageName; // App package name - String description; - String[] titles = new String[2]; // download titles. + int mId; // This first db _id for the download for the app + int mTotalCurrent = 0; + int mTotalTotal = 0; + int mTitleCount = 0; + String mPackageName; // App package name + String mDescription; + String[] mTitles = new String[2]; // download titles. /* * Add a second download to this notification item. */ void addItem(String title, int currentBytes, int totalBytes) { - totalCurrent += currentBytes; - if (totalBytes <= 0 || totalTotal == -1) { - totalTotal = -1; + mTotalCurrent += currentBytes; + if (totalBytes <= 0 || mTotalTotal == -1) { + mTotalTotal = -1; } else { - totalTotal += totalBytes; + mTotalTotal += totalBytes; } - if (titleCount < 2) { - titles[titleCount] = title; + if (mTitleCount < 2) { + mTitles[mTitleCount] = title; } - titleCount++; + mTitleCount++; } } @@ -148,9 +148,9 @@ class DownloadNotification { mNotifications.get(packageName).addItem(title, progress, max); } else { NotificationItem item = new NotificationItem(); - item.id = c.getInt(idColumn); - item.packageName = packageName; - item.description = c.getString(descColumn); + item.mId = c.getInt(idColumn); + item.mPackageName = packageName; + item.mDescription = c.getString(descColumn); String className = c.getString(classOwnerColumn); item.addItem(title, progress, max); mNotifications.put(packageName, item); @@ -171,26 +171,26 @@ class DownloadNotification { RemoteViews expandedView = new RemoteViews( "com.android.providers.downloads", R.layout.status_bar_ongoing_event_progress_bar); - StringBuilder title = new StringBuilder(item.titles[0]); - if (item.titleCount > 1) { + StringBuilder title = new StringBuilder(item.mTitles[0]); + if (item.mTitleCount > 1) { title.append(mContext.getString(R.string.notification_filename_separator)); - title.append(item.titles[1]); - n.number = item.titleCount; - if (item.titleCount > 2) { + title.append(item.mTitles[1]); + n.number = item.mTitleCount; + if (item.mTitleCount > 2) { title.append(mContext.getString(R.string.notification_filename_extras, - new Object[] { Integer.valueOf(item.titleCount - 2) })); + new Object[] { Integer.valueOf(item.mTitleCount - 2) })); } } else { expandedView.setTextViewText(R.id.description, - item.description); + item.mDescription); } expandedView.setTextViewText(R.id.title, title); expandedView.setProgressBar(R.id.progress_bar, - item.totalTotal, - item.totalCurrent, - item.totalTotal == -1); + item.mTotalTotal, + item.mTotalCurrent, + item.mTotalTotal == -1); expandedView.setTextViewText(R.id.progress_text, - getDownloadingText(item.totalTotal, item.totalCurrent)); + getDownloadingText(item.mTotalTotal, item.mTotalCurrent)); expandedView.setImageViewResource(R.id.appIcon, android.R.drawable.stat_sys_download); n.contentView = expandedView; @@ -198,12 +198,12 @@ class DownloadNotification { Intent intent = new Intent(Constants.ACTION_LIST); intent.setClassName("com.android.providers.downloads", DownloadReceiver.class.getName()); - intent.setData(Uri.parse(Downloads.CONTENT_URI + "/" + item.id)); - intent.putExtra("multiple", item.titleCount > 1); + intent.setData(Uri.parse(Downloads.CONTENT_URI + "/" + item.mId)); + intent.putExtra("multiple", item.mTitleCount > 1); n.contentIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0); - mNotificationMgr.notify(item.id, n); + mNotificationMgr.notify(item.mId, n); } } diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java index d86fdf97..23042b6a 100644 --- a/src/com/android/providers/downloads/DownloadProvider.java +++ b/src/com/android/providers/downloads/DownloadProvider.java @@ -26,10 +26,10 @@ import android.database.CrossProcessCursor; import android.database.Cursor; import android.database.CursorWindow; import android.database.CursorWrapper; +import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteQueryBuilder; -import android.database.SQLException; import android.net.Uri; import android.os.Binder; import android.os.ParcelFileDescriptor; @@ -40,7 +40,6 @@ import android.util.Log; import java.io.File; import java.io.FileNotFoundException; -import java.io.IOException; import java.util.HashSet; @@ -201,7 +200,7 @@ public final class DownloadProvider extends ContentProvider { db.execSQL("CREATE TABLE " + DB_TABLE + "(" + Downloads._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + Downloads.URI + " TEXT, " + - Constants.RETRY_AFTER___REDIRECT_COUNT + " INTEGER, " + + Constants.RETRY_AFTER_X_REDIRECT_COUNT + " INTEGER, " + Downloads.APP_DATA + " TEXT, " + Downloads.NO_INTEGRITY + " BOOLEAN, " + Downloads.FILENAME_HINT + " TEXT, " + diff --git a/src/com/android/providers/downloads/DownloadReceiver.java b/src/com/android/providers/downloads/DownloadReceiver.java index 03a37186..73eb0941 100644 --- a/src/com/android/providers/downloads/DownloadReceiver.java +++ b/src/com/android/providers/downloads/DownloadReceiver.java @@ -23,18 +23,15 @@ import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; import android.database.Cursor; -import android.provider.Downloads; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; +import android.provider.Downloads; import android.util.Config; import android.util.Log; import java.io.File; -import java.util.List; /** * Receives system broadcasts (boot, network connectivity) diff --git a/src/com/android/providers/downloads/DownloadService.java b/src/com/android/providers/downloads/DownloadService.java index d4b5f1e6..aaa5a687 100644 --- a/src/com/android/providers/downloads/DownloadService.java +++ b/src/com/android/providers/downloads/DownloadService.java @@ -26,20 +26,20 @@ import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; import android.content.Intent; +import android.content.ServiceConnection; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; -import android.content.ServiceConnection; +import android.database.CharArrayBuffer; import android.database.ContentObserver; import android.database.Cursor; -import android.database.CharArrayBuffer; import android.drm.mobile1.DrmRawContent; import android.media.IMediaScannerService; import android.net.Uri; -import android.os.RemoteException; import android.os.Environment; import android.os.Handler; import android.os.IBinder; import android.os.Process; +import android.os.RemoteException; import android.provider.Downloads; import android.util.Config; import android.util.Log; @@ -78,13 +78,13 @@ public class DownloadService extends Service { * The thread that updates the internal download list from the content * provider. */ - private UpdateThread updateThread; + private UpdateThread mUpdateThread; /** * Whether the internal download list should be updated from the content * provider. */ - private boolean pendingUpdate; + private boolean mPendingUpdate; /** * The ServiceConnection object that tells us when we're connected to and disconnected from @@ -107,7 +107,7 @@ public class DownloadService extends Service { /** * Array used when extracting strings from content provider */ - private CharArrayBuffer newChars; + private CharArrayBuffer mNewChars; /* ------------ Inner Classes ------------ */ @@ -247,10 +247,10 @@ public class DownloadService extends Service { */ private void updateFromProvider() { synchronized (this) { - pendingUpdate = true; - if (updateThread == null) { - updateThread = new UpdateThread(); - updateThread.start(); + mPendingUpdate = true; + if (mUpdateThread == null) { + mUpdateThread = new UpdateThread(); + mUpdateThread.start(); } } } @@ -269,12 +269,12 @@ public class DownloadService extends Service { long wakeUp = Long.MAX_VALUE; for (;;) { synchronized (DownloadService.this) { - if (updateThread != this) { + if (mUpdateThread != this) { throw new IllegalStateException( "multiple UpdateThreads in DownloadService"); } - if (!pendingUpdate) { - updateThread = null; + if (!mPendingUpdate) { + mUpdateThread = null; if (!keepService) { stopSelf(); } @@ -298,10 +298,10 @@ public class DownloadService extends Service { } } oldChars = null; - newChars = null; + mNewChars = null; return; } - pendingUpdate = false; + mPendingUpdate = false; } boolean networkAvailable = Helpers.isNetworkAvailable(DownloadService.this); boolean networkRoaming = Helpers.isNetworkRoaming(DownloadService.this); @@ -348,7 +348,7 @@ public class DownloadService extends Service { // We're beyond the end of the cursor but there's still some // stuff in the local array, which can only be junk if (Constants.LOGVV) { - int arrayId = ((DownloadInfo) mDownloads.get(arrayPos)).id; + int arrayId = ((DownloadInfo) mDownloads.get(arrayPos)).mId; Log.v(Constants.TAG, "Array update: trimming " + arrayId + " @ " + arrayPos); } @@ -383,7 +383,7 @@ public class DownloadService extends Service { cursor.moveToNext(); isAfterLast = cursor.isAfterLast(); } else { - int arrayId = mDownloads.get(arrayPos).id; + int arrayId = mDownloads.get(arrayPos).mId; if (arrayId < id) { // The array entry isn't in the cursor @@ -549,7 +549,7 @@ public class DownloadService extends Service { int statusColumn = cursor.getColumnIndexOrThrow(Downloads.STATUS); int failedColumn = cursor.getColumnIndexOrThrow(Constants.FAILED_CONNECTIONS); int retryRedirect = - cursor.getInt(cursor.getColumnIndexOrThrow(Constants.RETRY_AFTER___REDIRECT_COUNT)); + cursor.getInt(cursor.getColumnIndexOrThrow(Constants.RETRY_AFTER_X_REDIRECT_COUNT)); DownloadInfo info = new DownloadInfo( cursor.getInt(cursor.getColumnIndexOrThrow(Downloads._ID)), cursor.getString(cursor.getColumnIndexOrThrow(Downloads.URI)), @@ -578,38 +578,38 @@ public class DownloadService extends Service { if (Constants.LOGVV) { Log.v(Constants.TAG, "Service adding new entry"); - Log.v(Constants.TAG, "ID : " + info.id); - Log.v(Constants.TAG, "URI : " + ((info.uri != null) ? "yes" : "no")); - Log.v(Constants.TAG, "NO_INTEG: " + info.noIntegrity); - Log.v(Constants.TAG, "HINT : " + info.hint); - Log.v(Constants.TAG, "FILENAME: " + info.filename); - Log.v(Constants.TAG, "MIMETYPE: " + info.mimetype); - Log.v(Constants.TAG, "DESTINAT: " + info.destination); - Log.v(Constants.TAG, "VISIBILI: " + info.visibility); - Log.v(Constants.TAG, "CONTROL : " + info.control); - Log.v(Constants.TAG, "STATUS : " + info.status); - Log.v(Constants.TAG, "FAILED_C: " + info.numFailed); - Log.v(Constants.TAG, "RETRY_AF: " + info.retryAfter); - Log.v(Constants.TAG, "REDIRECT: " + info.redirectCount); - Log.v(Constants.TAG, "LAST_MOD: " + info.lastMod); - Log.v(Constants.TAG, "PACKAGE : " + info.pckg); - Log.v(Constants.TAG, "CLASS : " + info.clazz); - Log.v(Constants.TAG, "COOKIES : " + ((info.cookies != null) ? "yes" : "no")); - Log.v(Constants.TAG, "AGENT : " + info.userAgent); - Log.v(Constants.TAG, "REFERER : " + ((info.referer != null) ? "yes" : "no")); - Log.v(Constants.TAG, "TOTAL : " + info.totalBytes); - Log.v(Constants.TAG, "CURRENT : " + info.currentBytes); - Log.v(Constants.TAG, "ETAG : " + info.etag); - Log.v(Constants.TAG, "SCANNED : " + info.mediaScanned); + Log.v(Constants.TAG, "ID : " + info.mId); + Log.v(Constants.TAG, "URI : " + ((info.mUri != null) ? "yes" : "no")); + Log.v(Constants.TAG, "NO_INTEG: " + info.mNoIntegrity); + Log.v(Constants.TAG, "HINT : " + info.mHint); + Log.v(Constants.TAG, "FILENAME: " + info.mFileName); + Log.v(Constants.TAG, "MIMETYPE: " + info.mMimeType); + Log.v(Constants.TAG, "DESTINAT: " + info.mDestination); + Log.v(Constants.TAG, "VISIBILI: " + info.mVisibility); + Log.v(Constants.TAG, "CONTROL : " + info.mControl); + Log.v(Constants.TAG, "STATUS : " + info.mStatus); + Log.v(Constants.TAG, "FAILED_C: " + info.mNumFailed); + Log.v(Constants.TAG, "RETRY_AF: " + info.mRetryAfter); + Log.v(Constants.TAG, "REDIRECT: " + info.mRedirectCount); + Log.v(Constants.TAG, "LAST_MOD: " + info.mLastMod); + Log.v(Constants.TAG, "PACKAGE : " + info.mPackage); + Log.v(Constants.TAG, "CLASS : " + info.mClass); + Log.v(Constants.TAG, "COOKIES : " + ((info.mCookies != null) ? "yes" : "no")); + Log.v(Constants.TAG, "AGENT : " + info.mUserAgent); + Log.v(Constants.TAG, "REFERER : " + ((info.mReferer != null) ? "yes" : "no")); + Log.v(Constants.TAG, "TOTAL : " + info.mTotalBytes); + Log.v(Constants.TAG, "CURRENT : " + info.mCurrentBytes); + Log.v(Constants.TAG, "ETAG : " + info.mETag); + Log.v(Constants.TAG, "SCANNED : " + info.mMediaScanned); } mDownloads.add(arrayPos, info); - if (info.status == 0 - && (info.destination == Downloads.DESTINATION_EXTERNAL - || info.destination == Downloads.DESTINATION_CACHE_PARTITION_PURGEABLE) - && info.mimetype != null - && !DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING.equalsIgnoreCase(info.mimetype)) { + if (info.mStatus == 0 + && (info.mDestination == Downloads.DESTINATION_EXTERNAL + || info.mDestination == Downloads.DESTINATION_CACHE_PARTITION_PURGEABLE) + && info.mMimeType != null + && !DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING.equalsIgnoreCase(info.mMimeType)) { // Check to see if we are allowed to download this file. Only files // that can be handled by the platform can be downloaded. // special case DRM files, which we should always allow downloading. @@ -622,18 +622,18 @@ public class DownloadService extends Service { // prevent use from using content: so it's got to be file: or // nothing - mimetypeIntent.setDataAndType(Uri.fromParts("file", "", null), info.mimetype); + mimetypeIntent.setDataAndType(Uri.fromParts("file", "", null), info.mMimeType); List list = getPackageManager().queryIntentActivities(mimetypeIntent, PackageManager.MATCH_DEFAULT_ONLY); //Log.i(Constants.TAG, "*** QUERY " + mimetypeIntent + ": " + list); if (list.size() == 0) { if (Config.LOGD) { - Log.d(Constants.TAG, "no application to handle MIME type " + info.mimetype); + Log.d(Constants.TAG, "no application to handle MIME type " + info.mMimeType); } - info.status = Downloads.STATUS_NOT_ACCEPTABLE; + info.mStatus = Downloads.STATUS_NOT_ACCEPTABLE; - Uri uri = ContentUris.withAppendedId(Downloads.CONTENT_URI, info.id); + Uri uri = ContentUris.withAppendedId(Downloads.CONTENT_URI, info.mId); ContentValues values = new ContentValues(); values.put(Downloads.STATUS, Downloads.STATUS_NOT_ACCEPTABLE); getContentResolver().update(uri, values, null, null); @@ -646,29 +646,29 @@ public class DownloadService extends Service { if (info.isReadyToStart(now)) { if (Constants.LOGV) { Log.v(Constants.TAG, "Service spawning thread to handle new download " + - info.id); + info.mId); } - if (info.hasActiveThread) { + if (info.mHasActiveThread) { throw new IllegalStateException("Multiple threads on same download on insert"); } - if (info.status != Downloads.STATUS_RUNNING) { - info.status = Downloads.STATUS_RUNNING; + if (info.mStatus != Downloads.STATUS_RUNNING) { + info.mStatus = Downloads.STATUS_RUNNING; ContentValues values = new ContentValues(); - values.put(Downloads.STATUS, info.status); + values.put(Downloads.STATUS, info.mStatus); getContentResolver().update( - ContentUris.withAppendedId(Downloads.CONTENT_URI, info.id), + ContentUris.withAppendedId(Downloads.CONTENT_URI, info.mId), values, null, null); } DownloadThread downloader = new DownloadThread(this, info); - info.hasActiveThread = true; + info.mHasActiveThread = true; downloader.start(); } } else { - if (info.status == 0 - || info.status == Downloads.STATUS_PENDING - || info.status == Downloads.STATUS_RUNNING) { - info.status = Downloads.STATUS_RUNNING_PAUSED; - Uri uri = ContentUris.withAppendedId(Downloads.CONTENT_URI, info.id); + if (info.mStatus == 0 + || info.mStatus == Downloads.STATUS_PENDING + || info.mStatus == Downloads.STATUS_RUNNING) { + info.mStatus = Downloads.STATUS_RUNNING_PAUSED; + Uri uri = ContentUris.withAppendedId(Downloads.CONTENT_URI, info.mId); ContentValues values = new ContentValues(); values.put(Downloads.STATUS, Downloads.STATUS_RUNNING_PAUSED); getContentResolver().update(uri, values, null, null); @@ -685,63 +685,63 @@ public class DownloadService extends Service { DownloadInfo info = (DownloadInfo) mDownloads.get(arrayPos); int statusColumn = cursor.getColumnIndexOrThrow(Downloads.STATUS); int failedColumn = cursor.getColumnIndexOrThrow(Constants.FAILED_CONNECTIONS); - info.id = cursor.getInt(cursor.getColumnIndexOrThrow(Downloads._ID)); - info.uri = stringFromCursor(info.uri, cursor, Downloads.URI); - info.noIntegrity = + info.mId = cursor.getInt(cursor.getColumnIndexOrThrow(Downloads._ID)); + info.mUri = stringFromCursor(info.mUri, cursor, Downloads.URI); + info.mNoIntegrity = cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.NO_INTEGRITY)) == 1; - info.hint = stringFromCursor(info.hint, cursor, Downloads.FILENAME_HINT); - info.filename = stringFromCursor(info.filename, cursor, Downloads._DATA); - info.mimetype = stringFromCursor(info.mimetype, cursor, Downloads.MIMETYPE); - info.destination = cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.DESTINATION)); + info.mHint = stringFromCursor(info.mHint, cursor, Downloads.FILENAME_HINT); + info.mFileName = stringFromCursor(info.mFileName, cursor, Downloads._DATA); + info.mMimeType = stringFromCursor(info.mMimeType, cursor, Downloads.MIMETYPE); + info.mDestination = cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.DESTINATION)); int newVisibility = cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.VISIBILITY)); - if (info.visibility == Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED + if (info.mVisibility == Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED && newVisibility != Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED - && Downloads.isStatusCompleted(info.status)) { - mNotifier.mNotificationMgr.cancel(info.id); + && Downloads.isStatusCompleted(info.mStatus)) { + mNotifier.mNotificationMgr.cancel(info.mId); } - info.visibility = newVisibility; - synchronized(info) { - info.control = cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.CONTROL)); + info.mVisibility = newVisibility; + synchronized (info) { + info.mControl = cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.CONTROL)); } int newStatus = cursor.getInt(statusColumn); - if (!Downloads.isStatusCompleted(info.status) && Downloads.isStatusCompleted(newStatus)) { - mNotifier.mNotificationMgr.cancel(info.id); + if (!Downloads.isStatusCompleted(info.mStatus) && Downloads.isStatusCompleted(newStatus)) { + mNotifier.mNotificationMgr.cancel(info.mId); } - info.status = newStatus; - info.numFailed = cursor.getInt(failedColumn); + info.mStatus = newStatus; + info.mNumFailed = cursor.getInt(failedColumn); int retryRedirect = - cursor.getInt(cursor.getColumnIndexOrThrow(Constants.RETRY_AFTER___REDIRECT_COUNT)); - info.retryAfter = retryRedirect & 0xfffffff; - info.redirectCount = retryRedirect >> 28; - info.lastMod = cursor.getLong(cursor.getColumnIndexOrThrow(Downloads.LAST_MODIFICATION)); - info.pckg = stringFromCursor(info.pckg, cursor, Downloads.NOTIFICATION_PACKAGE); - info.clazz = stringFromCursor(info.clazz, cursor, Downloads.NOTIFICATION_CLASS); - info.cookies = stringFromCursor(info.cookies, cursor, Downloads.COOKIE_DATA); - info.userAgent = stringFromCursor(info.userAgent, cursor, Downloads.USER_AGENT); - info.referer = stringFromCursor(info.referer, cursor, Downloads.REFERER); - info.totalBytes = cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.TOTAL_BYTES)); - info.currentBytes = cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.CURRENT_BYTES)); - info.etag = stringFromCursor(info.etag, cursor, Constants.ETAG); - info.mediaScanned = + cursor.getInt(cursor.getColumnIndexOrThrow(Constants.RETRY_AFTER_X_REDIRECT_COUNT)); + info.mRetryAfter = retryRedirect & 0xfffffff; + info.mRedirectCount = retryRedirect >> 28; + info.mLastMod = cursor.getLong(cursor.getColumnIndexOrThrow(Downloads.LAST_MODIFICATION)); + info.mPackage = stringFromCursor(info.mPackage, cursor, Downloads.NOTIFICATION_PACKAGE); + info.mClass = stringFromCursor(info.mClass, cursor, Downloads.NOTIFICATION_CLASS); + info.mCookies = stringFromCursor(info.mCookies, cursor, Downloads.COOKIE_DATA); + info.mUserAgent = stringFromCursor(info.mUserAgent, cursor, Downloads.USER_AGENT); + info.mReferer = stringFromCursor(info.mReferer, cursor, Downloads.REFERER); + info.mTotalBytes = cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.TOTAL_BYTES)); + info.mCurrentBytes = cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.CURRENT_BYTES)); + info.mETag = stringFromCursor(info.mETag, cursor, Constants.ETAG); + info.mMediaScanned = cursor.getInt(cursor.getColumnIndexOrThrow(Constants.MEDIA_SCANNED)) == 1; if (info.canUseNetwork(networkAvailable, networkRoaming)) { if (info.isReadyToRestart(now)) { if (Constants.LOGV) { Log.v(Constants.TAG, "Service spawning thread to handle updated download " + - info.id); + info.mId); } - if (info.hasActiveThread) { + if (info.mHasActiveThread) { throw new IllegalStateException("Multiple threads on same download on update"); } - info.status = Downloads.STATUS_RUNNING; + info.mStatus = Downloads.STATUS_RUNNING; ContentValues values = new ContentValues(); - values.put(Downloads.STATUS, info.status); + values.put(Downloads.STATUS, info.mStatus); getContentResolver().update( - ContentUris.withAppendedId(Downloads.CONTENT_URI, info.id), + ContentUris.withAppendedId(Downloads.CONTENT_URI, info.mId), values, null, null); DownloadThread downloader = new DownloadThread(this, info); - info.hasActiveThread = true; + info.mHasActiveThread = true; downloader.start(); } } @@ -756,11 +756,11 @@ public class DownloadService extends Service { if (old == null) { return cursor.getString(index); } - if (newChars == null) { - newChars = new CharArrayBuffer(128); + if (mNewChars == null) { + mNewChars = new CharArrayBuffer(128); } - cursor.copyStringToBuffer(index, newChars); - int length = newChars.sizeCopied; + cursor.copyStringToBuffer(index, mNewChars); + int length = mNewChars.sizeCopied; if (length != old.length()) { return cursor.getString(index); } @@ -768,7 +768,7 @@ public class DownloadService extends Service { oldChars = new CharArrayBuffer(length); } char[] oldArray = oldChars.data; - char[] newArray = newChars.data; + char[] newArray = mNewChars.data; old.getChars(0, length, oldArray, 0); for (int i = length - 1; i >= 0; --i) { if (oldArray[i] != newArray[i]) { @@ -783,12 +783,12 @@ public class DownloadService extends Service { */ private void deleteDownload(int arrayPos) { DownloadInfo info = (DownloadInfo) mDownloads.get(arrayPos); - if (info.status == Downloads.STATUS_RUNNING) { - info.status = Downloads.STATUS_CANCELED; - } else if (info.destination != Downloads.DESTINATION_EXTERNAL && info.filename != null) { - new File(info.filename).delete(); + if (info.mStatus == Downloads.STATUS_RUNNING) { + info.mStatus = Downloads.STATUS_CANCELED; + } else if (info.mDestination != Downloads.DESTINATION_EXTERNAL && info.mFileName != null) { + new File(info.mFileName).delete(); } - mNotifier.mNotificationMgr.cancel(info.id); + mNotifier.mNotificationMgr.cancel(info.mId); mDownloads.remove(arrayPos); } @@ -802,13 +802,13 @@ public class DownloadService extends Service { */ private long nextAction(int arrayPos, long now) { DownloadInfo info = (DownloadInfo) mDownloads.get(arrayPos); - if (Downloads.isStatusCompleted(info.status)) { + if (Downloads.isStatusCompleted(info.mStatus)) { return -1; } - if (info.status != Downloads.STATUS_RUNNING_PAUSED) { + if (info.mStatus != Downloads.STATUS_RUNNING_PAUSED) { return 0; } - if (info.numFailed == 0) { + if (info.mNumFailed == 0) { return 0; } long when = info.restartTime(); @@ -831,10 +831,10 @@ public class DownloadService extends Service { */ private boolean shouldScanFile(int arrayPos) { DownloadInfo info = (DownloadInfo) mDownloads.get(arrayPos); - return !info.mediaScanned - && info.destination == Downloads.DESTINATION_EXTERNAL - && Downloads.isStatusSuccess(info.status) - && !DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING.equalsIgnoreCase(info.mimetype); + return !info.mMediaScanned + && info.mDestination == Downloads.DESTINATION_EXTERNAL + && Downloads.isStatusSuccess(info.mStatus) + && !DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING.equalsIgnoreCase(info.mMimeType); } /** @@ -854,9 +854,9 @@ public class DownloadService extends Service { if (mMediaScannerService != null) { try { if (Constants.LOGV) { - Log.v(Constants.TAG, "Scanning file " + info.filename); + Log.v(Constants.TAG, "Scanning file " + info.mFileName); } - mMediaScannerService.scanFile(info.filename, info.mimetype); + mMediaScannerService.scanFile(info.mFileName, info.mMimeType); if (cursor != null) { ContentValues values = new ContentValues(); values.put(Constants.MEDIA_SCANNED, 1); @@ -868,7 +868,7 @@ public class DownloadService extends Service { return true; } catch (RemoteException e) { if (Config.LOGD) { - Log.d(Constants.TAG, "Failed to scan file " + info.filename); + Log.d(Constants.TAG, "Failed to scan file " + info.mFileName); } } } diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java index 923e36d1..6e72b422 100644 --- a/src/com/android/providers/downloads/DownloadThread.java +++ b/src/com/android/providers/downloads/DownloadThread.java @@ -16,23 +16,19 @@ package com.android.providers.downloads; -import org.apache.http.client.methods.AbortableHttpRequest; +import org.apache.http.Header; +import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.HttpClient; import org.apache.http.entity.StringEntity; -import org.apache.http.Header; -import org.apache.http.HttpResponse; import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; import android.content.Intent; -import android.database.Cursor; import android.drm.mobile1.DrmRawContent; -import android.net.http.AndroidHttpClient; import android.net.Uri; +import android.net.http.AndroidHttpClient; import android.os.FileUtils; import android.os.PowerManager; import android.os.Process; @@ -44,10 +40,10 @@ import android.util.Log; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.io.InputStream; import java.io.IOException; -import java.io.UnsupportedEncodingException; +import java.io.InputStream; import java.net.URI; +import java.net.URISyntaxException; /** * Runs an actual download @@ -66,7 +62,7 @@ public class DownloadThread extends Thread { * Returns the user agent provided by the initiating app, or use the default one */ private String userAgent() { - String userAgent = mInfo.userAgent; + String userAgent = mInfo.mUserAgent; if (userAgent != null) { } if (userAgent == null) { @@ -84,15 +80,15 @@ public class DownloadThread extends Thread { int finalStatus = Downloads.STATUS_UNKNOWN_ERROR; boolean countRetry = false; int retryAfter = 0; - int redirectCount = mInfo.redirectCount; + int redirectCount = mInfo.mRedirectCount; String newUri = null; boolean gotData = false; String filename = null; - String mimeType = mInfo.mimetype; + String mimeType = mInfo.mMimeType; FileOutputStream stream = null; AndroidHttpClient client = null; PowerManager.WakeLock wakeLock = null; - Uri contentUri = Uri.parse(Downloads.CONTENT_URI + "/" + mInfo.id); + Uri contentUri = Uri.parse(Downloads.CONTENT_URI + "/" + mInfo.mId); try { boolean continuingDownload = false; @@ -111,12 +107,12 @@ public class DownloadThread extends Thread { wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.TAG); wakeLock.acquire(); - filename = mInfo.filename; + filename = mInfo.mFileName; if (filename != null) { if (!Helpers.isFilenameValid(filename)) { finalStatus = Downloads.STATUS_FILE_ERROR; notifyDownloadCompleted( - finalStatus, false, 0, 0, false, filename, null, mInfo.mimetype); + finalStatus, false, 0, 0, false, filename, null, mInfo.mMimeType); return; } // We're resuming a download that got interrupted @@ -127,7 +123,7 @@ public class DownloadThread extends Thread { // The download hadn't actually started, we can restart from scratch f.delete(); filename = null; - } else if (mInfo.etag == null && !mInfo.noIntegrity) { + } else if (mInfo.mETag == null && !mInfo.mNoIntegrity) { // Tough luck, that's not a resumable download if (Config.LOGD) { Log.d(Constants.TAG, @@ -136,16 +132,16 @@ public class DownloadThread extends Thread { f.delete(); finalStatus = Downloads.STATUS_PRECONDITION_FAILED; notifyDownloadCompleted( - finalStatus, false, 0, 0, false, filename, null, mInfo.mimetype); + finalStatus, false, 0, 0, false, filename, null, mInfo.mMimeType); return; } else { // All right, we'll be able to resume this download stream = new FileOutputStream(filename, true); bytesSoFar = (int) fileLength; - if (mInfo.totalBytes != -1) { - headerContentLength = Integer.toString(mInfo.totalBytes); + if (mInfo.mTotalBytes != -1) { + headerContentLength = Integer.toString(mInfo.mTotalBytes); } - headerETag = mInfo.etag; + headerETag = mInfo.mETag; continuingDownload = true; } } @@ -158,7 +154,7 @@ public class DownloadThread extends Thread { client = AndroidHttpClient.newInstance(userAgent()); - if (stream != null && mInfo.destination == Downloads.DESTINATION_EXTERNAL + if (stream != null && mInfo.mDestination == Downloads.DESTINATION_EXTERNAL && !DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING .equalsIgnoreCase(mimeType)) { try { @@ -181,17 +177,17 @@ public class DownloadThread extends Thread { http_request_loop: while (true) { // Prepares the request and fires it. - HttpGet request = new HttpGet(mInfo.uri); + HttpGet request = new HttpGet(mInfo.mUri); if (Constants.LOGV) { - Log.v(Constants.TAG, "initiating download for " + mInfo.uri); + Log.v(Constants.TAG, "initiating download for " + mInfo.mUri); } - if (mInfo.cookies != null) { - request.addHeader("Cookie", mInfo.cookies); + if (mInfo.mCookies != null) { + request.addHeader("Cookie", mInfo.mCookies); } - if (mInfo.referer != null) { - request.addHeader("Referer", mInfo.referer); + if (mInfo.mReferer != null) { + request.addHeader("Referer", mInfo.mReferer); } if (continuingDownload) { if (headerETag != null) { @@ -206,10 +202,10 @@ http_request_loop: } catch (IllegalArgumentException ex) { if (Constants.LOGV) { Log.d(Constants.TAG, "Arg exception trying to execute request for " + - mInfo.uri + " : " + ex); + mInfo.mUri + " : " + ex); } else if (Config.LOGD) { Log.d(Constants.TAG, "Arg exception trying to execute request for " + - mInfo.id + " : " + ex); + mInfo.mId + " : " + ex); } finalStatus = Downloads.STATUS_BAD_REQUEST; request.abort(); @@ -217,16 +213,16 @@ http_request_loop: } catch (IOException ex) { if (!Helpers.isNetworkAvailable(mContext)) { finalStatus = Downloads.STATUS_RUNNING_PAUSED; - } else if (mInfo.numFailed < Constants.MAX_RETRIES) { + } else if (mInfo.mNumFailed < Constants.MAX_RETRIES) { finalStatus = Downloads.STATUS_RUNNING_PAUSED; countRetry = true; } else { if (Constants.LOGV) { Log.d(Constants.TAG, "IOException trying to execute request for " + - mInfo.uri + " : " + ex); + mInfo.mUri + " : " + ex); } else if (Config.LOGD) { Log.d(Constants.TAG, "IOException trying to execute request for " + - mInfo.id + " : " + ex); + mInfo.mId + " : " + ex); } finalStatus = Downloads.STATUS_HTTP_DATA_ERROR; } @@ -235,7 +231,7 @@ http_request_loop: } int statusCode = response.getStatusLine().getStatusCode(); - if (statusCode == 503 && mInfo.numFailed < Constants.MAX_RETRIES) { + if (statusCode == 503 && mInfo.mNumFailed < Constants.MAX_RETRIES) { if (Constants.LOGVV) { Log.v(Constants.TAG, "got HTTP response code 503"); } @@ -256,7 +252,7 @@ http_request_loop: } else if (retryAfter > Constants.MAX_RETRY_AFTER) { retryAfter = Constants.MAX_RETRY_AFTER; } - retryAfter += Helpers.rnd.nextInt(Constants.MIN_RETRY_AFTER + 1); + retryAfter += Helpers.sRandom.nextInt(Constants.MIN_RETRY_AFTER + 1); retryAfter *= 1000; } } catch (NumberFormatException ex) { @@ -275,10 +271,10 @@ http_request_loop: } if (redirectCount >= Constants.MAX_REDIRECTS) { if (Constants.LOGV) { - Log.d(Constants.TAG, "too many redirects for download " + mInfo.id + - " at " + mInfo.uri); + Log.d(Constants.TAG, "too many redirects for download " + mInfo.mId + + " at " + mInfo.mUri); } else if (Config.LOGD) { - Log.d(Constants.TAG, "too many redirects for download " + mInfo.id); + Log.d(Constants.TAG, "too many redirects for download " + mInfo.mId); } finalStatus = Downloads.STATUS_TOO_MANY_REDIRECTS; request.abort(); @@ -289,7 +285,26 @@ http_request_loop: if (Constants.LOGVV) { Log.v(Constants.TAG, "Location :" + header.getValue()); } - newUri = new URI(mInfo.uri).resolve(new URI(header.getValue())).toString(); + try { + newUri = new URI(mInfo.mUri). + resolve(new URI(header.getValue())). + toString(); + } catch(URISyntaxException ex) { + if (Constants.LOGV) { + Log.d(Constants.TAG, + "Couldn't resolve redirect URI " + + header.getValue() + + " for " + + mInfo.mUri); + } else if (Config.LOGD) { + Log.d(Constants.TAG, + "Couldn't resolve redirect URI for download " + + mInfo.mId); + } + finalStatus = Downloads.STATUS_BAD_REQUEST; + request.abort(); + break http_request_loop; + } ++redirectCount; finalStatus = Downloads.STATUS_RUNNING_PAUSED; request.abort(); @@ -299,10 +314,10 @@ http_request_loop: if ((!continuingDownload && statusCode != Downloads.STATUS_SUCCESS) || (continuingDownload && statusCode != 206)) { if (Constants.LOGV) { - Log.d(Constants.TAG, "http error " + statusCode + " for " + mInfo.uri); + Log.d(Constants.TAG, "http error " + statusCode + " for " + mInfo.mUri); } else if (Config.LOGD) { Log.d(Constants.TAG, "http error " + statusCode + " for download " + - mInfo.id); + mInfo.mId); } if (Downloads.isStatusError(statusCode)) { finalStatus = statusCode; @@ -318,7 +333,7 @@ http_request_loop: } else { // Handles the response, saves the file if (Constants.LOGV) { - Log.v(Constants.TAG, "received response for " + mInfo.uri); + Log.v(Constants.TAG, "received response for " + mInfo.mUri); } if (!continuingDownload) { @@ -375,7 +390,7 @@ http_request_loop: Log.v(Constants.TAG, "Transfer-Encoding: " + headerTransferEncoding); } - if (!mInfo.noIntegrity && headerContentLength == null && + if (!mInfo.mNoIntegrity && headerContentLength == null && (headerTransferEncoding == null || !headerTransferEncoding.equalsIgnoreCase("chunked")) ) { @@ -389,23 +404,23 @@ http_request_loop: DownloadFileInfo fileInfo = Helpers.generateSaveFile( mContext, - mInfo.uri, - mInfo.hint, + mInfo.mUri, + mInfo.mHint, headerContentDisposition, headerContentLocation, mimeType, - mInfo.destination, + mInfo.mDestination, (headerContentLength != null) ? Integer.parseInt(headerContentLength) : 0); - if (fileInfo.filename == null) { - finalStatus = fileInfo.status; + if (fileInfo.mFileName == null) { + finalStatus = fileInfo.mStatus; request.abort(); break http_request_loop; } - filename = fileInfo.filename; - stream = fileInfo.stream; + filename = fileInfo.mFileName; + stream = fileInfo.mStream; if (Constants.LOGV) { - Log.v(Constants.TAG, "writing " + mInfo.uri + " to " + filename); + Log.v(Constants.TAG, "writing " + mInfo.mUri + " to " + filename); } ContentValues values = new ContentValues(); @@ -430,16 +445,19 @@ http_request_loop: } catch (IOException ex) { if (!Helpers.isNetworkAvailable(mContext)) { finalStatus = Downloads.STATUS_RUNNING_PAUSED; - } else if (mInfo.numFailed < Constants.MAX_RETRIES) { + } else if (mInfo.mNumFailed < Constants.MAX_RETRIES) { finalStatus = Downloads.STATUS_RUNNING_PAUSED; countRetry = true; } else { if (Constants.LOGV) { - Log.d(Constants.TAG, "IOException getting entity for " + mInfo.uri + - " : " + ex); + Log.d(Constants.TAG, + "IOException getting entity for " + + mInfo.mUri + + " : " + + ex); } else if (Config.LOGD) { Log.d(Constants.TAG, "IOException getting entity for download " + - mInfo.id + " : " + ex); + mInfo.mId + " : " + ex); } finalStatus = Downloads.STATUS_HTTP_DATA_ERROR; } @@ -454,13 +472,13 @@ http_request_loop: ContentValues values = new ContentValues(); values.put(Downloads.CURRENT_BYTES, bytesSoFar); mContext.getContentResolver().update(contentUri, values, null, null); - if (!mInfo.noIntegrity && headerETag == null) { + if (!mInfo.mNoIntegrity && headerETag == null) { if (Constants.LOGV) { - Log.v(Constants.TAG, "download IOException for " + mInfo.uri + + Log.v(Constants.TAG, "download IOException for " + mInfo.mUri + " : " + ex); } else if (Config.LOGD) { Log.d(Constants.TAG, "download IOException for download " + - mInfo.id + " : " + ex); + mInfo.mId + " : " + ex); } if (Config.LOGD) { Log.d(Constants.TAG, @@ -469,16 +487,16 @@ http_request_loop: finalStatus = Downloads.STATUS_PRECONDITION_FAILED; } else if (!Helpers.isNetworkAvailable(mContext)) { finalStatus = Downloads.STATUS_RUNNING_PAUSED; - } else if (mInfo.numFailed < Constants.MAX_RETRIES) { + } else if (mInfo.mNumFailed < Constants.MAX_RETRIES) { finalStatus = Downloads.STATUS_RUNNING_PAUSED; countRetry = true; } else { if (Constants.LOGV) { - Log.v(Constants.TAG, "download IOException for " + mInfo.uri + + Log.v(Constants.TAG, "download IOException for " + mInfo.mUri + " : " + ex); } else if (Config.LOGD) { Log.d(Constants.TAG, "download IOException for download " + - mInfo.id + " : " + ex); + mInfo.mId + " : " + ex); } finalStatus = Downloads.STATUS_HTTP_DATA_ERROR; } @@ -495,26 +513,26 @@ http_request_loop: if ((headerContentLength != null) && (bytesSoFar != Integer.parseInt(headerContentLength))) { - if (!mInfo.noIntegrity && headerETag == null) { + if (!mInfo.mNoIntegrity && headerETag == null) { if (Constants.LOGV) { Log.d(Constants.TAG, "mismatched content length " + - mInfo.uri); + mInfo.mUri); } else if (Config.LOGD) { Log.d(Constants.TAG, "mismatched content length for " + - mInfo.id); + mInfo.mId); } finalStatus = Downloads.STATUS_LENGTH_REQUIRED; } else if (!Helpers.isNetworkAvailable(mContext)) { finalStatus = Downloads.STATUS_RUNNING_PAUSED; - } else if (mInfo.numFailed < Constants.MAX_RETRIES) { + } else if (mInfo.mNumFailed < Constants.MAX_RETRIES) { finalStatus = Downloads.STATUS_RUNNING_PAUSED; countRetry = true; } else { if (Constants.LOGV) { - Log.v(Constants.TAG, "closed socket for " + mInfo.uri); + Log.v(Constants.TAG, "closed socket for " + mInfo.mUri); } else if (Config.LOGD) { Log.d(Constants.TAG, "closed socket for download " + - mInfo.id); + mInfo.mId); } finalStatus = Downloads.STATUS_HTTP_DATA_ERROR; } @@ -529,7 +547,7 @@ http_request_loop: stream = new FileOutputStream(filename, true); } stream.write(data, 0, bytesRead); - if (mInfo.destination == Downloads.DESTINATION_EXTERNAL + if (mInfo.mDestination == Downloads.DESTINATION_EXTERNAL && !DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING .equalsIgnoreCase(mimeType)) { try { @@ -567,30 +585,30 @@ http_request_loop: } if (Constants.LOGVV) { - Log.v(Constants.TAG, "downloaded " + bytesSoFar + " for " + mInfo.uri); + Log.v(Constants.TAG, "downloaded " + bytesSoFar + " for " + mInfo.mUri); } - synchronized(mInfo) { - if (mInfo.control == Downloads.CONTROL_PAUSED) { + synchronized (mInfo) { + if (mInfo.mControl == Downloads.CONTROL_PAUSED) { if (Constants.LOGV) { - Log.v(Constants.TAG, "paused " + mInfo.uri); + Log.v(Constants.TAG, "paused " + mInfo.mUri); } finalStatus = Downloads.STATUS_RUNNING_PAUSED; request.abort(); break http_request_loop; } } - if (mInfo.status == Downloads.STATUS_CANCELED) { + if (mInfo.mStatus == Downloads.STATUS_CANCELED) { if (Constants.LOGV) { - Log.d(Constants.TAG, "canceled " + mInfo.uri); + Log.d(Constants.TAG, "canceled " + mInfo.mUri); } else if (Config.LOGD) { - // Log.d(Constants.TAG, "canceled id " + mInfo.id); + // Log.d(Constants.TAG, "canceled id " + mInfo.mId); } finalStatus = Downloads.STATUS_CANCELED; break http_request_loop; } } if (Constants.LOGV) { - Log.v(Constants.TAG, "download completed for " + mInfo.uri); + Log.v(Constants.TAG, "download completed for " + mInfo.mUri); } finalStatus = Downloads.STATUS_SUCCESS; } @@ -602,16 +620,16 @@ http_request_loop: } finalStatus = Downloads.STATUS_FILE_ERROR; // falls through to the code that reports an error - } catch (Exception ex) { //sometimes the socket code throws unchecked exceptions + } catch (RuntimeException ex) { //sometimes the socket code throws unchecked exceptions if (Constants.LOGV) { - Log.d(Constants.TAG, "Exception for " + mInfo.uri, ex); + Log.d(Constants.TAG, "Exception for " + mInfo.mUri, ex); } else if (Config.LOGD) { - Log.d(Constants.TAG, "Exception for id " + mInfo.id, ex); + Log.d(Constants.TAG, "Exception for id " + mInfo.mId, ex); } finalStatus = Downloads.STATUS_UNKNOWN_ERROR; // falls through to the code that reports an error } finally { - mInfo.hasActiveThread = false; + mInfo.mHasActiveThread = false; if (wakeLock != null) { wakeLock.release(); wakeLock = null; @@ -685,17 +703,17 @@ http_request_loop: } values.put(Downloads.MIMETYPE, mimeType); values.put(Downloads.LAST_MODIFICATION, System.currentTimeMillis()); - values.put(Constants.RETRY_AFTER___REDIRECT_COUNT, retryAfter + (redirectCount << 28)); + values.put(Constants.RETRY_AFTER_X_REDIRECT_COUNT, retryAfter + (redirectCount << 28)); if (!countRetry) { values.put(Constants.FAILED_CONNECTIONS, 0); } else if (gotData) { values.put(Constants.FAILED_CONNECTIONS, 1); } else { - values.put(Constants.FAILED_CONNECTIONS, mInfo.numFailed + 1); + values.put(Constants.FAILED_CONNECTIONS, mInfo.mNumFailed + 1); } mContext.getContentResolver().update( - ContentUris.withAppendedId(Downloads.CONTENT_URI, mInfo.id), values, null, null); + ContentUris.withAppendedId(Downloads.CONTENT_URI, mInfo.mId), values, null, null); } /** @@ -703,7 +721,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.id); + Uri uri = Uri.parse(Downloads.CONTENT_URI + "/" + mInfo.mId); mInfo.sendIntentIfRequested(uri, mContext); } diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java index 89a57313..4ebc8181 100644 --- a/src/com/android/providers/downloads/Helpers.java +++ b/src/com/android/providers/downloads/Helpers.java @@ -40,16 +40,16 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.util.List; import java.util.Random; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.Set; /** * Some helper functions for the download manager */ public class Helpers { - public static Random rnd = new Random(SystemClock.uptimeMillis()); + public static Random sRandom = new Random(SystemClock.uptimeMillis()); /** Regex used to parse content-disposition headers */ private static final Pattern CONTENT_DISPOSITION_PATTERN = @@ -412,7 +412,7 @@ public class Helpers { if (Constants.LOGVV) { Log.v(Constants.TAG, "file with sequence number " + sequence + " exists"); } - sequence += rnd.nextInt(magnitude) + 1; + sequence += sRandom.nextInt(magnitude) + 1; } } return null; @@ -756,7 +756,7 @@ public class Helpers { // quoted strings if (chars[mOffset] == '\'') { ++mOffset; - while(mOffset < chars.length) { + while (mOffset < chars.length) { if (chars[mOffset] == '\'') { if (mOffset + 1 < chars.length && chars[mOffset + 1] == '\'') { ++mOffset; -- cgit v1.2.3