diff options
author | Steve Howard <showard@google.com> | 2010-09-12 18:53:31 -0700 |
---|---|---|
committer | Steve Howard <showard@google.com> | 2010-09-14 19:00:40 -0700 |
commit | 3d55d829c03fe78ad8cdab119293efb6c6e49c64 (patch) | |
tree | fb8feb9c23b83108546048b0488033279de63635 /tests/src/com/android | |
parent | 33671e9c1e9ffa3776ed987bddeb70a04daa7cfe (diff) | |
download | android_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 'tests/src/com/android')
-rw-r--r-- | tests/src/com/android/providers/downloads/AbstractDownloadManagerFunctionalTest.java | 3 | ||||
-rw-r--r-- | tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java | 16 |
2 files changed, 15 insertions, 4 deletions
diff --git a/tests/src/com/android/providers/downloads/AbstractDownloadManagerFunctionalTest.java b/tests/src/com/android/providers/downloads/AbstractDownloadManagerFunctionalTest.java index 3e4bccc3..d04fd2de 100644 --- a/tests/src/com/android/providers/downloads/AbstractDownloadManagerFunctionalTest.java +++ b/tests/src/com/android/providers/downloads/AbstractDownloadManagerFunctionalTest.java @@ -165,7 +165,8 @@ public abstract class AbstractDownloadManagerFunctionalTest extends } private boolean isDatabaseEmpty() { - Cursor cursor = mResolver.query(Downloads.CONTENT_URI, null, null, null, null); + Cursor cursor = mResolver.query(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, + null, null, null, null); try { return cursor.getCount() == 0; } finally { diff --git a/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java b/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java index e48ce22e..d577e2c8 100644 --- a/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java +++ b/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java @@ -29,6 +29,8 @@ import tests.http.RecordedRequest; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.util.List; @@ -89,9 +91,8 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { assertEquals(REQUEST_PATH, request.getPath()); Uri localUri = Uri.parse(download.getStringField(DownloadManager.COLUMN_LOCAL_URI)); - assertEquals("file", localUri.getScheme()); - assertStartsWith("//" + Environment.getDownloadCacheDirectory().getPath(), - localUri.getSchemeSpecificPart()); + assertEquals("content", localUri.getScheme()); + checkUriContent(localUri); assertEquals("text/plain", download.getStringField(DownloadManager.COLUMN_MEDIA_TYPE)); int size = FILE_CONTENT.length(); @@ -103,6 +104,15 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { checkCompleteDownload(download); } + private void checkUriContent(Uri uri) throws FileNotFoundException, IOException { + InputStream inputStream = mResolver.openInputStream(uri); + try { + assertEquals(FILE_CONTENT, readStream(inputStream)); + } finally { + inputStream.close(); + } + } + public void testTitleAndDescription() throws Exception { Download download = enqueueRequest(getRequest() .setTitle("my title") |