summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/DownloadService.java
diff options
context:
space:
mode:
authorSteve Howard <showard@google.com>2010-09-12 18:53:31 -0700
committerSteve Howard <showard@google.com>2010-09-14 19:00:40 -0700
commit3d55d829c03fe78ad8cdab119293efb6c6e49c64 (patch)
treefb8feb9c23b83108546048b0488033279de63635 /src/com/android/providers/downloads/DownloadService.java
parent33671e9c1e9ffa3776ed987bddeb70a04daa7cfe (diff)
downloadandroid_packages_providers_DownloadProvider-3d55d829c03fe78ad8cdab119293efb6c6e49c64.tar.gz
android_packages_providers_DownloadProvider-3d55d829c03fe78ad8cdab119293efb6c6e49c64.tar.bz2
android_packages_providers_DownloadProvider-3d55d829c03fe78ad8cdab119293efb6c6e49c64.zip
New URI structure with "my_downloads" and "all_downloads"
This change introduces a second view into the download manager database via a set of URIs starting with /all_downloads, renaming the original /download URIs to /my_downloads. In addition to making things more clear, this change allows the downloads UI to grant permissions on individual downloads to viewer apps. The old semantics were: * for ordinary callers, /download included only downloads initiated by the calling UID * for intraprocess calls or calls by root, /download included all downloads The new semantics are * /my_downloads always includes only downloads initiated by the calling UID, and requires only INTERNET permission. It could just as well require no permission, but that's not possible in the framework, since path-permissions can only broaden access, not tighten it. It doesn't matter, because these URIs are useless without INTERNET permission -- if a user can't initiate downloads, there's no reason to read this. * /all_downloads always includes all downloads on the system, and requires the new permission ACCESS_ALL_DOWNLOADS. This permission is currently protectionLevel=signature -- this could be relaxed later to support third-party download managers. All download manager code has been changed to use /all_downloads URIs, except when passing a URI to another app. In making this change across the download manager code, I've taken some liberties in cleaning things up. Other apps are unchanged and will use /my_downloads. Finally, this incorporates changes to DownloadManager to return a content URI for /cache downloads -- the download UI no longer assumes it's a file URI, and it grants permissions to the receiver of the VIEW intent. The public API test has also been updated. I've also fixed some null cursor checking in DownloadManager. Change-Id: I05a501eb4388249fe80c43724405657c950d7238
Diffstat (limited to 'src/com/android/providers/downloads/DownloadService.java')
-rw-r--r--src/com/android/providers/downloads/DownloadService.java38
1 files changed, 15 insertions, 23 deletions
diff --git a/src/com/android/providers/downloads/DownloadService.java b/src/com/android/providers/downloads/DownloadService.java
index 6d9ee220..b85fb902 100644
--- a/src/com/android/providers/downloads/DownloadService.java
+++ b/src/com/android/providers/downloads/DownloadService.java
@@ -211,7 +211,7 @@ public class DownloadService extends Service {
mDownloads = Lists.newArrayList();
mObserver = new DownloadManagerContentObserver();
- getContentResolver().registerContentObserver(Downloads.Impl.CONTENT_URI,
+ getContentResolver().registerContentObserver(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI,
true, mObserver);
mMediaScannerService = null;
@@ -313,7 +313,7 @@ public class DownloadService extends Service {
}
long now = mSystemFacade.currentTimeMillis();
- Cursor cursor = getContentResolver().query(Downloads.Impl.CONTENT_URI,
+ Cursor cursor = getContentResolver().query(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI,
null, null, null, Downloads.Impl._ID);
if (cursor == null) {
@@ -482,7 +482,7 @@ public class DownloadService extends Service {
// when running the simulator).
return;
}
- HashSet<String> fileSet = new HashSet();
+ HashSet<String> fileSet = new HashSet<String>();
for (int i = 0; i < files.length; i++) {
if (files[i].getName().equals(Constants.KNOWN_SPURIOUS_FILENAME)) {
continue;
@@ -493,7 +493,7 @@ public class DownloadService extends Service {
fileSet.add(files[i].getPath());
}
- Cursor cursor = getContentResolver().query(Downloads.Impl.CONTENT_URI,
+ Cursor cursor = getContentResolver().query(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI,
new String[] { Downloads.Impl._DATA }, null, null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
@@ -517,7 +517,7 @@ public class DownloadService extends Service {
* Drops old rows from the database to prevent it from growing too large
*/
private void trimDatabase() {
- Cursor cursor = getContentResolver().query(Downloads.Impl.CONTENT_URI,
+ Cursor cursor = getContentResolver().query(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI,
new String[] { Downloads.Impl._ID },
Downloads.Impl.COLUMN_STATUS + " >= '200'", null,
Downloads.Impl.COLUMN_LAST_MODIFICATION);
@@ -530,9 +530,9 @@ public class DownloadService extends Service {
int numDelete = cursor.getCount() - Constants.MAX_DOWNLOADS;
int columnId = cursor.getColumnIndexOrThrow(Downloads.Impl._ID);
while (numDelete > 0) {
- getContentResolver().delete(
- ContentUris.withAppendedId(Downloads.Impl.CONTENT_URI,
- cursor.getLong(columnId)), null, null);
+ Uri downloadUri = ContentUris.withAppendedId(
+ Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, cursor.getLong(columnId));
+ getContentResolver().delete(downloadUri, null, null);
if (!cursor.moveToNext()) {
break;
}
@@ -601,16 +601,13 @@ public class DownloadService extends Service {
//Log.i(Constants.TAG, "*** QUERY " + mimetypeIntent + ": " + list);
if (ri == null) {
- if (Config.LOGD) {
- Log.d(Constants.TAG, "no application to handle MIME type " + info.mMimeType);
- }
+ Log.d(Constants.TAG, "no application to handle MIME type " + info.mMimeType);
info.mStatus = Downloads.Impl.STATUS_NOT_ACCEPTABLE;
- Uri uri = ContentUris.withAppendedId(Downloads.Impl.CONTENT_URI, info.mId);
ContentValues values = new ContentValues();
values.put(Downloads.Impl.COLUMN_STATUS, Downloads.Impl.STATUS_NOT_ACCEPTABLE);
- getContentResolver().update(uri, values, null, null);
- info.sendIntentIfRequested(uri);
+ getContentResolver().update(info.getAllDownloadsUri(), values, null, null);
+ info.sendIntentIfRequested();
return;
}
}
@@ -624,7 +621,7 @@ public class DownloadService extends Service {
* Updates the local copy of the info about a download.
*/
private void updateDownload(Cursor cursor, int arrayPos, long now) {
- DownloadInfo info = (DownloadInfo) mDownloads.get(arrayPos);
+ DownloadInfo info = mDownloads.get(arrayPos);
int statusColumn = cursor.getColumnIndexOrThrow(Downloads.Impl.COLUMN_STATUS);
int failedColumn = cursor.getColumnIndexOrThrow(Constants.FAILED_CONNECTIONS);
info.mId = cursor.getInt(cursor.getColumnIndexOrThrow(Downloads.Impl._ID));
@@ -785,7 +782,7 @@ public class DownloadService extends Service {
* Returns true if the file has been properly scanned.
*/
private boolean scanFile(Cursor cursor, int arrayPos) {
- DownloadInfo info = (DownloadInfo) mDownloads.get(arrayPos);
+ DownloadInfo info = mDownloads.get(arrayPos);
synchronized (this) {
if (mMediaScannerService != null) {
try {
@@ -796,16 +793,11 @@ public class DownloadService extends Service {
if (cursor != null) {
ContentValues values = new ContentValues();
values.put(Constants.MEDIA_SCANNED, 1);
- getContentResolver().update(ContentUris.withAppendedId(
- Downloads.Impl.CONTENT_URI, cursor.getLong(
- cursor.getColumnIndexOrThrow(Downloads.Impl._ID))),
- values, null, null);
+ getContentResolver().update(info.getAllDownloadsUri(), values, null, null);
}
return true;
} catch (RemoteException e) {
- if (Config.LOGD) {
- Log.d(Constants.TAG, "Failed to scan file " + info.mFileName);
- }
+ Log.d(Constants.TAG, "Failed to scan file " + info.mFileName);
}
}
}