From 3ca67748bc92eac89f731796c5597ff1fbe9217b Mon Sep 17 00:00:00 2001 From: Vasu Nori Date: Thu, 4 Nov 2010 15:03:31 -0700 Subject: changes to support CL: I1f5dd734e394db0056579a3a0c26862fee27981e 1. if an application designates a downloaded file to be mediascanner scannable or not, store that fact in database. 2. use the above to determine whether a file shoudl be mediascanned or not in DownloadService 3. implement code to return mimetype for the new Uri "/public_downloads" introduced in CL: I1f5dd734e394db0056579a3a0c26862fee27981e Change-Id: I5c062ad6d1b58306044cee49ff3827e908d27fd9 --- .../android/providers/downloads/DownloadInfo.java | 2 +- .../providers/downloads/DownloadProvider.java | 23 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/com/android/providers/downloads/DownloadInfo.java b/src/com/android/providers/downloads/DownloadInfo.java index b024ca6c..49d42732 100644 --- a/src/com/android/providers/downloads/DownloadInfo.java +++ b/src/com/android/providers/downloads/DownloadInfo.java @@ -84,7 +84,7 @@ public class DownloadInfo { info.mTotalBytes = getLong(Downloads.Impl.COLUMN_TOTAL_BYTES); info.mCurrentBytes = getLong(Downloads.Impl.COLUMN_CURRENT_BYTES); info.mETag = getString(info.mETag, Constants.ETAG); - info.mMediaScanned = getInt(Constants.MEDIA_SCANNED) == 1; + info.mMediaScanned = getInt(Constants.MEDIA_SCANNED) > 0; info.mDeleted = getInt(Downloads.Impl.COLUMN_DELETED) == 1; info.mMediaProviderUri = getString(info.mMediaProviderUri, Downloads.Impl.COLUMN_MEDIAPROVIDER_URI); diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java index f6f1b940..ee669a7c 100644 --- a/src/com/android/providers/downloads/DownloadProvider.java +++ b/src/com/android/providers/downloads/DownloadProvider.java @@ -16,6 +16,7 @@ package com.android.providers.downloads; +import android.app.DownloadManager; import android.content.ContentProvider; import android.content.ContentUris; import android.content.ContentValues; @@ -26,6 +27,7 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.database.Cursor; +import android.database.DatabaseUtils; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; @@ -35,6 +37,7 @@ import android.os.Environment; import android.os.ParcelFileDescriptor; import android.os.Process; import android.provider.Downloads; +import android.text.TextUtils; import android.util.Log; import com.google.common.annotations.VisibleForTesting; @@ -76,6 +79,11 @@ public final class DownloadProvider extends ContentProvider { private static final int ALL_DOWNLOADS_ID = 4; /** URI matcher constant for the URI of a download's request headers */ private static final int REQUEST_HEADERS_URI = 5; + /** URI matcher constant for the public URI returned by + * {@link DownloadManager#getUriForDownloadedFile(long)} if the given downloaded file + * is publicly accessible. + */ + private static final int PUBLIC_DOWNLOAD_ID = 6; static { sURIMatcher.addURI("downloads", "my_downloads", MY_DOWNLOADS); sURIMatcher.addURI("downloads", "my_downloads/#", MY_DOWNLOADS_ID); @@ -93,6 +101,9 @@ public final class DownloadProvider extends ContentProvider { sURIMatcher.addURI("downloads", "download/#/" + Downloads.Impl.RequestHeaders.URI_SEGMENT, REQUEST_HEADERS_URI); + sURIMatcher.addURI("downloads", + Downloads.Impl.PUBLICLY_ACCESSIBLE_DOWNLOADS_URI_SEGMENT + "/#", + PUBLIC_DOWNLOAD_ID); } /** Different base URIs that could be used to access an individual download */ @@ -421,6 +432,15 @@ public final class DownloadProvider extends ContentProvider { case MY_DOWNLOADS_ID: { return DOWNLOAD_TYPE; } + case PUBLIC_DOWNLOAD_ID: { + // return the mimetype of this id from the database + final String id = getDownloadIdFromUri(uri); + final SQLiteDatabase db = mOpenHelper.getReadableDatabase(); + return DatabaseUtils.stringForQuery(db, + "SELECT " + Downloads.Impl.COLUMN_MIME_TYPE + " FROM " + DB_TABLE + + " WHERE " + Downloads.Impl._ID + " = ?", + new String[]{id}); + } default: { if (Constants.LOGV) { Log.v(Constants.TAG, "calling getType on an unknown URI: " + uri); @@ -963,7 +983,8 @@ public final class DownloadProvider extends ContentProvider { int uriMatch) { SqlSelection selection = new SqlSelection(); selection.appendClause(where, whereArgs); - if (uriMatch == MY_DOWNLOADS_ID || uriMatch == ALL_DOWNLOADS_ID) { + if (uriMatch == MY_DOWNLOADS_ID || uriMatch == ALL_DOWNLOADS_ID || + uriMatch == PUBLIC_DOWNLOAD_ID) { selection.appendClause(Downloads.Impl._ID + " = ?", getDownloadIdFromUri(uri)); } if (uriMatch == MY_DOWNLOADS || uriMatch == MY_DOWNLOADS_ID) { -- cgit v1.2.3