From 59910f4a9ce953ea74c8db759448f227c96796b3 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Queru Date: Tue, 20 Jan 2009 11:05:32 -0800 Subject: Use the new download manager APIs introduced in change 7400 --- .../android/providers/downloads/DownloadInfo.java | 4 +- .../providers/downloads/DownloadNotification.java | 45 ++++--- .../providers/downloads/DownloadProvider.java | 140 ++++++++++----------- .../providers/downloads/DownloadReceiver.java | 23 ++-- .../providers/downloads/DownloadService.java | 86 +++++++------ .../providers/downloads/DownloadThread.java | 20 +-- src/com/android/providers/downloads/Helpers.java | 8 +- 7 files changed, 173 insertions(+), 153 deletions(-) (limited to 'src') diff --git a/src/com/android/providers/downloads/DownloadInfo.java b/src/com/android/providers/downloads/DownloadInfo.java index 24bdbfa3..336a2a0d 100644 --- a/src/com/android/providers/downloads/DownloadInfo.java +++ b/src/com/android/providers/downloads/DownloadInfo.java @@ -87,10 +87,10 @@ public class DownloadInfo { public void sendIntentIfRequested(Uri contentUri, Context context) { if (mPackage != null && mClass != null) { - Intent intent = new Intent(Downloads.DOWNLOAD_COMPLETED_ACTION); + Intent intent = new Intent(Downloads.ACTION_DOWNLOAD_COMPLETED); intent.setClassName(mPackage, mClass); if (mExtras != null) { - intent.putExtra(Downloads.NOTIFICATION_EXTRAS, mExtras); + intent.putExtra(Downloads.COLUMN_NOTIFICATION_EXTRAS, mExtras); } // We only send the content: URI, for security reasons. Otherwise, malicious // applications would have an easier time spoofing download results by diff --git a/src/com/android/providers/downloads/DownloadNotification.java b/src/com/android/providers/downloads/DownloadNotification.java index 68373271..9f54190e 100644 --- a/src/com/android/providers/downloads/DownloadNotification.java +++ b/src/com/android/providers/downloads/DownloadNotification.java @@ -43,14 +43,15 @@ class DownloadNotification { static final String LOGTAG = "DownloadNotification"; static final String WHERE_RUNNING = - "(" + Downloads.STATUS + " >= '100') AND (" + - Downloads.STATUS + " <= '199') AND (" + - Downloads.VISIBILITY + " IS NULL OR " + - Downloads.VISIBILITY + " == '" + Downloads.VISIBILITY_VISIBLE + "' OR " + - Downloads.VISIBILITY + " == '" + Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED + "')"; + "(" + Downloads.COLUMN_STATUS + " >= '100') AND (" + + Downloads.COLUMN_STATUS + " <= '199') AND (" + + Downloads.COLUMN_VISIBILITY + " IS NULL OR " + + Downloads.COLUMN_VISIBILITY + " == '" + Downloads.VISIBILITY_VISIBLE + "' OR " + + Downloads.COLUMN_VISIBILITY + + " == '" + Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED + "')"; static final String WHERE_COMPLETED = - Downloads.STATUS + " >= '200' AND " + - Downloads.VISIBILITY + " == '" + Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED + "'"; + Downloads.COLUMN_STATUS + " >= '200' AND " + + Downloads.COLUMN_VISIBILITY + " == '" + Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED + "'"; /** @@ -110,11 +111,14 @@ class DownloadNotification { // Active downloads Cursor c = mContext.getContentResolver().query( Downloads.CONTENT_URI, new String [] { - Downloads._ID, Downloads.TITLE, Downloads.DESCRIPTION, - Downloads.NOTIFICATION_PACKAGE, - Downloads.NOTIFICATION_CLASS, - Downloads.CURRENT_BYTES, Downloads.TOTAL_BYTES, - Downloads.STATUS, Downloads._DATA + Downloads._ID, + Downloads.COLUMN_TITLE, + Downloads.COLUMN_DESCRIPTION, + Downloads.COLUMN_NOTIFICATION_PACKAGE, + Downloads.COLUMN_NOTIFICATION_CLASS, + Downloads.COLUMN_CURRENT_BYTES, + Downloads.COLUMN_TOTAL_BYTES, + Downloads.COLUMN_STATUS, Downloads._DATA }, WHERE_RUNNING, null, Downloads._ID); @@ -212,12 +216,17 @@ class DownloadNotification { // Completed downloads Cursor c = mContext.getContentResolver().query( Downloads.CONTENT_URI, new String [] { - Downloads._ID, Downloads.TITLE, Downloads.DESCRIPTION, - Downloads.NOTIFICATION_PACKAGE, - Downloads.NOTIFICATION_CLASS, - Downloads.CURRENT_BYTES, Downloads.TOTAL_BYTES, - Downloads.STATUS, Downloads._DATA, - Downloads.LAST_MODIFICATION, Downloads.DESTINATION + Downloads._ID, + Downloads.COLUMN_TITLE, + Downloads.COLUMN_DESCRIPTION, + Downloads.COLUMN_NOTIFICATION_PACKAGE, + Downloads.COLUMN_NOTIFICATION_CLASS, + Downloads.COLUMN_CURRENT_BYTES, + Downloads.COLUMN_TOTAL_BYTES, + Downloads.COLUMN_STATUS, + Downloads._DATA, + Downloads.COLUMN_LAST_MODIFICATION, + Downloads.COLUMN_DESTINATION }, WHERE_COMPLETED, null, Downloads._ID); diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java index 23042b6a..25d25e36 100644 --- a/src/com/android/providers/downloads/DownloadProvider.java +++ b/src/com/android/providers/downloads/DownloadProvider.java @@ -77,19 +77,19 @@ public final class DownloadProvider extends ContentProvider { private static final String[] sAppReadableColumnsArray = new String[] { Downloads._ID, - Downloads.APP_DATA, + Downloads.COLUMN_APP_DATA, Downloads._DATA, - Downloads.MIMETYPE, - Downloads.VISIBILITY, - Downloads.CONTROL, - Downloads.STATUS, - Downloads.LAST_MODIFICATION, - Downloads.NOTIFICATION_PACKAGE, - Downloads.NOTIFICATION_CLASS, - Downloads.TOTAL_BYTES, - Downloads.CURRENT_BYTES, - Downloads.TITLE, - Downloads.DESCRIPTION + Downloads.COLUMN_MIME_TYPE, + Downloads.COLUMN_VISIBILITY, + Downloads.COLUMN_CONTROL, + Downloads.COLUMN_STATUS, + Downloads.COLUMN_LAST_MODIFICATION, + Downloads.COLUMN_NOTIFICATION_PACKAGE, + Downloads.COLUMN_NOTIFICATION_CLASS, + Downloads.COLUMN_TOTAL_BYTES, + Downloads.COLUMN_CURRENT_BYTES, + Downloads.COLUMN_TITLE, + Downloads.COLUMN_DESCRIPTION }; private static HashSet sAppReadableColumnsSet; @@ -199,34 +199,34 @@ public final class DownloadProvider extends ContentProvider { try { db.execSQL("CREATE TABLE " + DB_TABLE + "(" + Downloads._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - Downloads.URI + " TEXT, " + + Downloads.COLUMN_URI + " TEXT, " + Constants.RETRY_AFTER_X_REDIRECT_COUNT + " INTEGER, " + - Downloads.APP_DATA + " TEXT, " + - Downloads.NO_INTEGRITY + " BOOLEAN, " + - Downloads.FILENAME_HINT + " TEXT, " + + Downloads.COLUMN_APP_DATA + " TEXT, " + + Downloads.COLUMN_NO_INTEGRITY + " BOOLEAN, " + + Downloads.COLUMN_FILE_NAME_HINT + " TEXT, " + Constants.OTA_UPDATE + " BOOLEAN, " + Downloads._DATA + " TEXT, " + - Downloads.MIMETYPE + " TEXT, " + - Downloads.DESTINATION + " INTEGER, " + + Downloads.COLUMN_MIME_TYPE + " TEXT, " + + Downloads.COLUMN_DESTINATION + " INTEGER, " + Constants.NO_SYSTEM_FILES + " BOOLEAN, " + - Downloads.VISIBILITY + " INTEGER, " + - Downloads.CONTROL + " INTEGER, " + - Downloads.STATUS + " INTEGER, " + + Downloads.COLUMN_VISIBILITY + " INTEGER, " + + Downloads.COLUMN_CONTROL + " INTEGER, " + + Downloads.COLUMN_STATUS + " INTEGER, " + Constants.FAILED_CONNECTIONS + " INTEGER, " + - Downloads.LAST_MODIFICATION + " BIGINT, " + - Downloads.NOTIFICATION_PACKAGE + " TEXT, " + - Downloads.NOTIFICATION_CLASS + " TEXT, " + - Downloads.NOTIFICATION_EXTRAS + " TEXT, " + - Downloads.COOKIE_DATA + " TEXT, " + - Downloads.USER_AGENT + " TEXT, " + - Downloads.REFERER + " TEXT, " + - Downloads.TOTAL_BYTES + " INTEGER, " + - Downloads.CURRENT_BYTES + " INTEGER, " + + Downloads.COLUMN_LAST_MODIFICATION + " BIGINT, " + + Downloads.COLUMN_NOTIFICATION_PACKAGE + " TEXT, " + + Downloads.COLUMN_NOTIFICATION_CLASS + " TEXT, " + + Downloads.COLUMN_NOTIFICATION_EXTRAS + " TEXT, " + + Downloads.COLUMN_COOKIE_DATA + " TEXT, " + + Downloads.COLUMN_USER_AGENT + " TEXT, " + + Downloads.COLUMN_REFERER + " TEXT, " + + Downloads.COLUMN_TOTAL_BYTES + " INTEGER, " + + Downloads.COLUMN_CURRENT_BYTES + " INTEGER, " + Constants.ETAG + " TEXT, " + Constants.UID + " INTEGER, " + - Downloads.OTHER_UID + " INTEGER, " + - Downloads.TITLE + " TEXT, " + - Downloads.DESCRIPTION + " TEXT, " + + Downloads.COLUMN_OTHER_UID + " INTEGER, " + + Downloads.COLUMN_TITLE + " TEXT, " + + Downloads.COLUMN_DESCRIPTION + " TEXT, " + Constants.MEDIA_SCANNED + " BOOLEAN);"); } catch (SQLException ex) { Log.e(Constants.TAG, "couldn't create table in downloads database"); @@ -262,12 +262,12 @@ public final class DownloadProvider extends ContentProvider { ContentValues filteredValues = new ContentValues(); - copyString(Downloads.URI, values, filteredValues); - copyString(Downloads.APP_DATA, values, filteredValues); - copyBoolean(Downloads.NO_INTEGRITY, values, filteredValues); - copyString(Downloads.FILENAME_HINT, values, filteredValues); - copyString(Downloads.MIMETYPE, values, filteredValues); - Integer i = values.getAsInteger(Downloads.DESTINATION); + copyString(Downloads.COLUMN_URI, values, filteredValues); + copyString(Downloads.COLUMN_APP_DATA, values, filteredValues); + copyBoolean(Downloads.COLUMN_NO_INTEGRITY, values, filteredValues); + copyString(Downloads.COLUMN_FILE_NAME_HINT, values, filteredValues); + copyString(Downloads.COLUMN_MIME_TYPE, values, filteredValues); + Integer i = values.getAsInteger(Downloads.COLUMN_DESTINATION); if (i != null) { if (getContext().checkCallingPermission(Downloads.PERMISSION_ACCESS_ADVANCED) != PackageManager.PERMISSION_GRANTED @@ -275,51 +275,51 @@ public final class DownloadProvider extends ContentProvider { && i != Downloads.DESTINATION_CACHE_PARTITION_PURGEABLE) { throw new SecurityException("unauthorized destination code"); } - filteredValues.put(Downloads.DESTINATION, i); + filteredValues.put(Downloads.COLUMN_DESTINATION, i); if (i != Downloads.DESTINATION_EXTERNAL && - values.getAsInteger(Downloads.VISIBILITY) == null) { - filteredValues.put(Downloads.VISIBILITY, Downloads.VISIBILITY_HIDDEN); + values.getAsInteger(Downloads.COLUMN_VISIBILITY) == null) { + filteredValues.put(Downloads.COLUMN_VISIBILITY, Downloads.VISIBILITY_HIDDEN); } } - copyInteger(Downloads.VISIBILITY, values, filteredValues); - copyInteger(Downloads.CONTROL, values, filteredValues); - filteredValues.put(Downloads.STATUS, Downloads.STATUS_PENDING); - filteredValues.put(Downloads.LAST_MODIFICATION, System.currentTimeMillis()); - String pckg = values.getAsString(Downloads.NOTIFICATION_PACKAGE); - String clazz = values.getAsString(Downloads.NOTIFICATION_CLASS); + copyInteger(Downloads.COLUMN_VISIBILITY, values, filteredValues); + copyInteger(Downloads.COLUMN_CONTROL, values, filteredValues); + filteredValues.put(Downloads.COLUMN_STATUS, Downloads.STATUS_PENDING); + filteredValues.put(Downloads.COLUMN_LAST_MODIFICATION, System.currentTimeMillis()); + String pckg = values.getAsString(Downloads.COLUMN_NOTIFICATION_PACKAGE); + String clazz = values.getAsString(Downloads.COLUMN_NOTIFICATION_CLASS); if (pckg != null && clazz != null) { int uid = Binder.getCallingUid(); try { if (uid == 0 || getContext().getPackageManager().getApplicationInfo(pckg, 0).uid == uid) { - filteredValues.put(Downloads.NOTIFICATION_PACKAGE, pckg); - filteredValues.put(Downloads.NOTIFICATION_CLASS, clazz); + filteredValues.put(Downloads.COLUMN_NOTIFICATION_PACKAGE, pckg); + filteredValues.put(Downloads.COLUMN_NOTIFICATION_CLASS, clazz); } } catch (PackageManager.NameNotFoundException ex) { /* ignored for now */ } } - copyString(Downloads.NOTIFICATION_EXTRAS, values, filteredValues); - copyString(Downloads.COOKIE_DATA, values, filteredValues); - copyString(Downloads.USER_AGENT, values, filteredValues); - copyString(Downloads.REFERER, values, filteredValues); + copyString(Downloads.COLUMN_NOTIFICATION_EXTRAS, values, filteredValues); + copyString(Downloads.COLUMN_COOKIE_DATA, values, filteredValues); + copyString(Downloads.COLUMN_USER_AGENT, values, filteredValues); + copyString(Downloads.COLUMN_REFERER, values, filteredValues); if (getContext().checkCallingPermission(Downloads.PERMISSION_ACCESS_ADVANCED) == PackageManager.PERMISSION_GRANTED) { - copyInteger(Downloads.OTHER_UID, values, filteredValues); + copyInteger(Downloads.COLUMN_OTHER_UID, values, filteredValues); } filteredValues.put(Constants.UID, Binder.getCallingUid()); if (Binder.getCallingUid() == 0) { copyInteger(Constants.UID, values, filteredValues); } - copyString(Downloads.TITLE, values, filteredValues); - copyString(Downloads.DESCRIPTION, values, filteredValues); + copyString(Downloads.COLUMN_TITLE, values, filteredValues); + copyString(Downloads.COLUMN_DESCRIPTION, values, filteredValues); if (Constants.LOGVV) { Log.v(Constants.TAG, "initiating download with UID " + filteredValues.getAsInteger(Constants.UID)); - if (filteredValues.containsKey(Downloads.OTHER_UID)) { + if (filteredValues.containsKey(Downloads.COLUMN_OTHER_UID)) { Log.v(Constants.TAG, "other UID " + - filteredValues.getAsInteger(Downloads.OTHER_UID)); + filteredValues.getAsInteger(Downloads.COLUMN_OTHER_UID)); } } @@ -384,7 +384,7 @@ public final class DownloadProvider extends ContentProvider { qb.appendWhere(" AND "); } qb.appendWhere("( " + Constants.UID + "=" + Binder.getCallingUid() + " OR " - + Downloads.OTHER_UID + "=" + Binder.getCallingUid() + " )"); + + Downloads.COLUMN_OTHER_UID + "=" + Binder.getCallingUid() + " )"); emptyWhere = false; if (projection == null) { @@ -481,16 +481,16 @@ public final class DownloadProvider extends ContentProvider { ContentValues filteredValues; if (Binder.getCallingPid() != Process.myPid()) { filteredValues = new ContentValues(); - copyString(Downloads.APP_DATA, values, filteredValues); - copyInteger(Downloads.VISIBILITY, values, filteredValues); - Integer i = values.getAsInteger(Downloads.CONTROL); + copyString(Downloads.COLUMN_APP_DATA, values, filteredValues); + copyInteger(Downloads.COLUMN_VISIBILITY, values, filteredValues); + Integer i = values.getAsInteger(Downloads.COLUMN_CONTROL); if (i != null) { - filteredValues.put(Downloads.CONTROL, i); + filteredValues.put(Downloads.COLUMN_CONTROL, i); startService = true; } - copyInteger(Downloads.CONTROL, values, filteredValues); - copyString(Downloads.TITLE, values, filteredValues); - copyString(Downloads.DESCRIPTION, values, filteredValues); + copyInteger(Downloads.COLUMN_CONTROL, values, filteredValues); + copyString(Downloads.COLUMN_TITLE, values, filteredValues); + copyString(Downloads.COLUMN_DESCRIPTION, values, filteredValues); } else { filteredValues = values; } @@ -515,7 +515,7 @@ public final class DownloadProvider extends ContentProvider { } if (Binder.getCallingPid() != Process.myPid() && Binder.getCallingUid() != 0) { myWhere += " AND ( " + Constants.UID + "=" + Binder.getCallingUid() + " OR " - + Downloads.OTHER_UID + "=" + Binder.getCallingUid() + " )"; + + Downloads.COLUMN_OTHER_UID + "=" + Binder.getCallingUid() + " )"; } if (filteredValues.size() > 0) { count = db.update(DB_TABLE, filteredValues, myWhere, whereArgs); @@ -571,7 +571,7 @@ public final class DownloadProvider extends ContentProvider { } if (Binder.getCallingPid() != Process.myPid() && Binder.getCallingUid() != 0) { myWhere += " AND ( " + Constants.UID + "=" + Binder.getCallingUid() + " OR " - + Downloads.OTHER_UID + "=" + Binder.getCallingUid() + " )"; + + Downloads.COLUMN_OTHER_UID + "=" + Binder.getCallingUid() + " )"; } count = db.delete(DB_TABLE, myWhere, whereArgs); break; @@ -665,7 +665,7 @@ public final class DownloadProvider extends ContentProvider { throw new FileNotFoundException("couldn't open file"); } else { ContentValues values = new ContentValues(); - values.put(Downloads.LAST_MODIFICATION, System.currentTimeMillis()); + values.put(Downloads.COLUMN_LAST_MODIFICATION, System.currentTimeMillis()); update(uri, values, null, null); } return ret; diff --git a/src/com/android/providers/downloads/DownloadReceiver.java b/src/com/android/providers/downloads/DownloadReceiver.java index 73eb0941..c0ccad3a 100644 --- a/src/com/android/providers/downloads/DownloadReceiver.java +++ b/src/com/android/providers/downloads/DownloadReceiver.java @@ -71,20 +71,22 @@ public class DownloadReceiver extends BroadcastReceiver { intent.getData(), null, null, null, null); if (cursor != null) { if (cursor.moveToFirst()) { - int statusColumn = cursor.getColumnIndexOrThrow(Downloads.STATUS); + int statusColumn = cursor.getColumnIndexOrThrow(Downloads.COLUMN_STATUS); int status = cursor.getInt(statusColumn); - int visibilityColumn = cursor.getColumnIndexOrThrow(Downloads.VISIBILITY); + int visibilityColumn = + cursor.getColumnIndexOrThrow(Downloads.COLUMN_VISIBILITY); int visibility = cursor.getInt(visibilityColumn); if (Downloads.isStatusCompleted(status) && visibility == Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) { ContentValues values = new ContentValues(); - values.put(Downloads.VISIBILITY, Downloads.VISIBILITY_VISIBLE); + values.put(Downloads.COLUMN_VISIBILITY, Downloads.VISIBILITY_VISIBLE); context.getContentResolver().update(intent.getData(), values, null, null); } if (intent.getAction().equals(Constants.ACTION_OPEN)) { int filenameColumn = cursor.getColumnIndexOrThrow(Downloads._DATA); - int mimetypeColumn = cursor.getColumnIndexOrThrow(Downloads.MIMETYPE); + int mimetypeColumn = + cursor.getColumnIndexOrThrow(Downloads.COLUMN_MIME_TYPE); String filename = cursor.getString(filenameColumn); String mimetype = cursor.getString(mimetypeColumn); Uri path = Uri.parse(filename); @@ -106,13 +108,13 @@ public class DownloadReceiver extends BroadcastReceiver { } } else { int packageColumn = - cursor.getColumnIndexOrThrow(Downloads.NOTIFICATION_PACKAGE); + cursor.getColumnIndexOrThrow(Downloads.COLUMN_NOTIFICATION_PACKAGE); int classColumn = - cursor.getColumnIndexOrThrow(Downloads.NOTIFICATION_CLASS); + cursor.getColumnIndexOrThrow(Downloads.COLUMN_NOTIFICATION_CLASS); String pckg = cursor.getString(packageColumn); String clazz = cursor.getString(classColumn); if (pckg != null && clazz != null) { - Intent appIntent = new Intent(Downloads.NOTIFICATION_CLICKED_ACTION); + Intent appIntent = new Intent(Downloads.ACTION_NOTIFICATION_CLICKED); appIntent.setClassName(pckg, clazz); if (intent.getBooleanExtra("multiple", true)) { appIntent.setData(Downloads.CONTENT_URI); @@ -138,14 +140,15 @@ public class DownloadReceiver extends BroadcastReceiver { intent.getData(), null, null, null, null); if (cursor != null) { if (cursor.moveToFirst()) { - int statusColumn = cursor.getColumnIndexOrThrow(Downloads.STATUS); + int statusColumn = cursor.getColumnIndexOrThrow(Downloads.COLUMN_STATUS); int status = cursor.getInt(statusColumn); - int visibilityColumn = cursor.getColumnIndexOrThrow(Downloads.VISIBILITY); + int visibilityColumn = + cursor.getColumnIndexOrThrow(Downloads.COLUMN_VISIBILITY); int visibility = cursor.getInt(visibilityColumn); if (Downloads.isStatusCompleted(status) && visibility == Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) { ContentValues values = new ContentValues(); - values.put(Downloads.VISIBILITY, Downloads.VISIBILITY_VISIBLE); + values.put(Downloads.COLUMN_VISIBILITY, Downloads.VISIBILITY_VISIBLE); context.getContentResolver().update(intent.getData(), values, null, null); } } diff --git a/src/com/android/providers/downloads/DownloadService.java b/src/com/android/providers/downloads/DownloadService.java index aaa5a687..4a1d2f8e 100644 --- a/src/com/android/providers/downloads/DownloadService.java +++ b/src/com/android/providers/downloads/DownloadService.java @@ -516,8 +516,8 @@ public class DownloadService extends Service { private void trimDatabase() { Cursor cursor = getContentResolver().query(Downloads.CONTENT_URI, new String[] { Downloads._ID }, - Downloads.STATUS + " >= '200'", null, - Downloads.LAST_MODIFICATION); + Downloads.COLUMN_STATUS + " >= '200'", null, + Downloads.COLUMN_LAST_MODIFICATION); if (cursor == null) { // This isn't good - if we can't do basic queries in our database, nothing's gonna work Log.e(Constants.TAG, "null cursor in trimDatabase"); @@ -546,33 +546,35 @@ public class DownloadService extends Service { private void insertDownload( Cursor cursor, int arrayPos, boolean networkAvailable, boolean networkRoaming, long now) { - int statusColumn = cursor.getColumnIndexOrThrow(Downloads.STATUS); + int statusColumn = cursor.getColumnIndexOrThrow(Downloads.COLUMN_STATUS); int failedColumn = cursor.getColumnIndexOrThrow(Constants.FAILED_CONNECTIONS); int retryRedirect = 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)), - cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.NO_INTEGRITY)) == 1, - cursor.getString(cursor.getColumnIndexOrThrow(Downloads.FILENAME_HINT)), + cursor.getString(cursor.getColumnIndexOrThrow(Downloads.COLUMN_URI)), + cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.COLUMN_NO_INTEGRITY)) == 1, + cursor.getString(cursor.getColumnIndexOrThrow(Downloads.COLUMN_FILE_NAME_HINT)), cursor.getString(cursor.getColumnIndexOrThrow(Downloads._DATA)), - cursor.getString(cursor.getColumnIndexOrThrow(Downloads.MIMETYPE)), - cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.DESTINATION)), - cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.VISIBILITY)), - cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.CONTROL)), + cursor.getString(cursor.getColumnIndexOrThrow(Downloads.COLUMN_MIME_TYPE)), + cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.COLUMN_DESTINATION)), + cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.COLUMN_VISIBILITY)), + cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.COLUMN_CONTROL)), cursor.getInt(statusColumn), cursor.getInt(failedColumn), retryRedirect & 0xfffffff, retryRedirect >> 28, - cursor.getLong(cursor.getColumnIndexOrThrow(Downloads.LAST_MODIFICATION)), - cursor.getString(cursor.getColumnIndexOrThrow(Downloads.NOTIFICATION_PACKAGE)), - cursor.getString(cursor.getColumnIndexOrThrow(Downloads.NOTIFICATION_CLASS)), - cursor.getString(cursor.getColumnIndexOrThrow(Downloads.NOTIFICATION_EXTRAS)), - cursor.getString(cursor.getColumnIndexOrThrow(Downloads.COOKIE_DATA)), - cursor.getString(cursor.getColumnIndexOrThrow(Downloads.USER_AGENT)), - cursor.getString(cursor.getColumnIndexOrThrow(Downloads.REFERER)), - cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.TOTAL_BYTES)), - cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.CURRENT_BYTES)), + cursor.getLong(cursor.getColumnIndexOrThrow(Downloads.COLUMN_LAST_MODIFICATION)), + cursor.getString(cursor.getColumnIndexOrThrow( + Downloads.COLUMN_NOTIFICATION_PACKAGE)), + cursor.getString(cursor.getColumnIndexOrThrow(Downloads.COLUMN_NOTIFICATION_CLASS)), + cursor.getString(cursor.getColumnIndexOrThrow( + Downloads.COLUMN_NOTIFICATION_EXTRAS)), + cursor.getString(cursor.getColumnIndexOrThrow(Downloads.COLUMN_COOKIE_DATA)), + cursor.getString(cursor.getColumnIndexOrThrow(Downloads.COLUMN_USER_AGENT)), + cursor.getString(cursor.getColumnIndexOrThrow(Downloads.COLUMN_REFERER)), + cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.COLUMN_TOTAL_BYTES)), + cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.COLUMN_CURRENT_BYTES)), cursor.getString(cursor.getColumnIndexOrThrow(Constants.ETAG)), cursor.getInt(cursor.getColumnIndexOrThrow(Constants.MEDIA_SCANNED)) == 1); @@ -635,7 +637,7 @@ public class DownloadService extends Service { Uri uri = ContentUris.withAppendedId(Downloads.CONTENT_URI, info.mId); ContentValues values = new ContentValues(); - values.put(Downloads.STATUS, Downloads.STATUS_NOT_ACCEPTABLE); + values.put(Downloads.COLUMN_STATUS, Downloads.STATUS_NOT_ACCEPTABLE); getContentResolver().update(uri, values, null, null); info.sendIntentIfRequested(uri, this); return; @@ -654,7 +656,7 @@ public class DownloadService extends Service { if (info.mStatus != Downloads.STATUS_RUNNING) { info.mStatus = Downloads.STATUS_RUNNING; ContentValues values = new ContentValues(); - values.put(Downloads.STATUS, info.mStatus); + values.put(Downloads.COLUMN_STATUS, info.mStatus); getContentResolver().update( ContentUris.withAppendedId(Downloads.CONTENT_URI, info.mId), values, null, null); @@ -670,7 +672,7 @@ public class DownloadService extends Service { 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); + values.put(Downloads.COLUMN_STATUS, Downloads.STATUS_RUNNING_PAUSED); getContentResolver().update(uri, values, null, null); } } @@ -683,17 +685,19 @@ public class DownloadService extends Service { Cursor cursor, int arrayPos, boolean networkAvailable, boolean networkRoaming, long now) { DownloadInfo info = (DownloadInfo) mDownloads.get(arrayPos); - int statusColumn = cursor.getColumnIndexOrThrow(Downloads.STATUS); + int statusColumn = cursor.getColumnIndexOrThrow(Downloads.COLUMN_STATUS); int failedColumn = cursor.getColumnIndexOrThrow(Constants.FAILED_CONNECTIONS); info.mId = cursor.getInt(cursor.getColumnIndexOrThrow(Downloads._ID)); - info.mUri = stringFromCursor(info.mUri, cursor, Downloads.URI); + info.mUri = stringFromCursor(info.mUri, cursor, Downloads.COLUMN_URI); info.mNoIntegrity = - cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.NO_INTEGRITY)) == 1; - info.mHint = stringFromCursor(info.mHint, cursor, Downloads.FILENAME_HINT); + cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.COLUMN_NO_INTEGRITY)) == 1; + info.mHint = stringFromCursor(info.mHint, cursor, Downloads.COLUMN_FILE_NAME_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)); + info.mMimeType = stringFromCursor(info.mMimeType, cursor, Downloads.COLUMN_MIME_TYPE); + info.mDestination = cursor.getInt(cursor.getColumnIndexOrThrow( + Downloads.COLUMN_DESTINATION)); + int newVisibility = cursor.getInt(cursor.getColumnIndexOrThrow( + Downloads.COLUMN_VISIBILITY)); if (info.mVisibility == Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED && newVisibility != Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED && Downloads.isStatusCompleted(info.mStatus)) { @@ -701,7 +705,7 @@ public class DownloadService extends Service { } info.mVisibility = newVisibility; synchronized (info) { - info.mControl = cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.CONTROL)); + info.mControl = cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.COLUMN_CONTROL)); } int newStatus = cursor.getInt(statusColumn); if (!Downloads.isStatusCompleted(info.mStatus) && Downloads.isStatusCompleted(newStatus)) { @@ -713,14 +717,18 @@ public class DownloadService extends Service { 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.mLastMod = cursor.getLong(cursor.getColumnIndexOrThrow( + Downloads.COLUMN_LAST_MODIFICATION)); + info.mPackage = stringFromCursor( + info.mPackage, cursor, Downloads.COLUMN_NOTIFICATION_PACKAGE); + info.mClass = stringFromCursor(info.mClass, cursor, Downloads.COLUMN_NOTIFICATION_CLASS); + info.mCookies = stringFromCursor(info.mCookies, cursor, Downloads.COLUMN_COOKIE_DATA); + info.mUserAgent = stringFromCursor(info.mUserAgent, cursor, Downloads.COLUMN_USER_AGENT); + info.mReferer = stringFromCursor(info.mReferer, cursor, Downloads.COLUMN_REFERER); + info.mTotalBytes = cursor.getInt(cursor.getColumnIndexOrThrow( + Downloads.COLUMN_TOTAL_BYTES)); + info.mCurrentBytes = cursor.getInt(cursor.getColumnIndexOrThrow( + Downloads.COLUMN_CURRENT_BYTES)); info.mETag = stringFromCursor(info.mETag, cursor, Constants.ETAG); info.mMediaScanned = cursor.getInt(cursor.getColumnIndexOrThrow(Constants.MEDIA_SCANNED)) == 1; @@ -736,7 +744,7 @@ public class DownloadService extends Service { } info.mStatus = Downloads.STATUS_RUNNING; ContentValues values = new ContentValues(); - values.put(Downloads.STATUS, info.mStatus); + values.put(Downloads.COLUMN_STATUS, info.mStatus); getContentResolver().update( ContentUris.withAppendedId(Downloads.CONTENT_URI, info.mId), values, null, null); diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java index 6e72b422..127cc46d 100644 --- a/src/com/android/providers/downloads/DownloadThread.java +++ b/src/com/android/providers/downloads/DownloadThread.java @@ -429,13 +429,13 @@ http_request_loop: values.put(Constants.ETAG, headerETag); } if (mimeType != null) { - values.put(Downloads.MIMETYPE, mimeType); + values.put(Downloads.COLUMN_MIME_TYPE, mimeType); } int contentLength = -1; if (headerContentLength != null) { contentLength = Integer.parseInt(headerContentLength); } - values.put(Downloads.TOTAL_BYTES, contentLength); + values.put(Downloads.COLUMN_TOTAL_BYTES, contentLength); mContext.getContentResolver().update(contentUri, values, null, null); } @@ -470,7 +470,7 @@ http_request_loop: bytesRead = entityStream.read(data); } catch (IOException ex) { ContentValues values = new ContentValues(); - values.put(Downloads.CURRENT_BYTES, bytesSoFar); + values.put(Downloads.COLUMN_CURRENT_BYTES, bytesSoFar); mContext.getContentResolver().update(contentUri, values, null, null); if (!mInfo.mNoIntegrity && headerETag == null) { if (Constants.LOGV) { @@ -505,9 +505,9 @@ http_request_loop: } if (bytesRead == -1) { // success ContentValues values = new ContentValues(); - values.put(Downloads.CURRENT_BYTES, bytesSoFar); + values.put(Downloads.COLUMN_CURRENT_BYTES, bytesSoFar); if (headerContentLength == null) { - values.put(Downloads.TOTAL_BYTES, bytesSoFar); + values.put(Downloads.COLUMN_TOTAL_BYTES, bytesSoFar); } mContext.getContentResolver().update(contentUri, values, null, null); if ((headerContentLength != null) @@ -577,7 +577,7 @@ http_request_loop: && now - timeLastNotification > Constants.MIN_PROGRESS_TIME) { ContentValues values = new ContentValues(); - values.put(Downloads.CURRENT_BYTES, bytesSoFar); + values.put(Downloads.COLUMN_CURRENT_BYTES, bytesSoFar); mContext.getContentResolver().update( contentUri, values, null, null); bytesNotified = bytesSoFar; @@ -696,13 +696,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.STATUS, status); + values.put(Downloads.COLUMN_STATUS, status); values.put(Downloads._DATA, filename); if (uri != null) { - values.put(Downloads.URI, uri); + values.put(Downloads.COLUMN_URI, uri); } - values.put(Downloads.MIMETYPE, mimeType); - values.put(Downloads.LAST_MODIFICATION, System.currentTimeMillis()); + values.put(Downloads.COLUMN_MIME_TYPE, mimeType); + values.put(Downloads.COLUMN_LAST_MODIFICATION, System.currentTimeMillis()); values.put(Constants.RETRY_AFTER_X_REDIRECT_COUNT, retryAfter + (redirectCount << 28)); if (!countRetry) { values.put(Constants.FAILED_CONNECTIONS, 0); diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java index 4ebc8181..0226eba4 100644 --- a/src/com/android/providers/downloads/Helpers.java +++ b/src/com/android/providers/downloads/Helpers.java @@ -428,11 +428,11 @@ public class Helpers { Downloads.CONTENT_URI, null, "( " + - Downloads.STATUS + " = " + Downloads.STATUS_SUCCESS + " AND " + - Downloads.DESTINATION + " = " + Downloads.DESTINATION_CACHE_PARTITION_PURGEABLE - + " )", + Downloads.COLUMN_STATUS + " = " + Downloads.STATUS_SUCCESS + " AND " + + Downloads.COLUMN_DESTINATION + + " = " + Downloads.DESTINATION_CACHE_PARTITION_PURGEABLE + " )", null, - Downloads.LAST_MODIFICATION); + Downloads.COLUMN_LAST_MODIFICATION); if (cursor == null) { return false; } -- cgit v1.2.3