From d635ac295850ba23d528c02b1e5c6eb44b64b22b Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Sat, 15 Jul 2017 12:23:05 -0600 Subject: Allocate space using new StorageManager API. Instead of reaching directly into PackageManager, use the new StorageManager API to allocate disk space for downloads. This wraps both clearing cached files and fallocate() into a single method. Remove support for storing downloads on the /cache partition, which doesn't exist on many devices. Bug: 63057877 Test: bit DownloadProviderTests:* Exempt-From-Owner-Approval: Bug 63673347 Change-Id: I5749f7a2f7ded9157fea763dc652bf4da88d86ff --- .../AbstractDownloadProviderFunctionalTest.java | 35 ++++++++-------------- 1 file changed, 12 insertions(+), 23 deletions(-) (limited to 'tests/src/com/android/providers/downloads/AbstractDownloadProviderFunctionalTest.java') diff --git a/tests/src/com/android/providers/downloads/AbstractDownloadProviderFunctionalTest.java b/tests/src/com/android/providers/downloads/AbstractDownloadProviderFunctionalTest.java index 813252a8..13d2c36e 100644 --- a/tests/src/com/android/providers/downloads/AbstractDownloadProviderFunctionalTest.java +++ b/tests/src/com/android/providers/downloads/AbstractDownloadProviderFunctionalTest.java @@ -171,8 +171,8 @@ public abstract class AbstractDownloadProviderFunctionalTest extends Helpers.setSystemFacade(mSystemFacade); mSystemFacade.setUp(); - assertTrue(isDatabaseEmpty()); // ensure we're not messing with real data - assertTrue(isDatabaseSecureAgainstBadSelection()); + assertDatabaseEmpty(); // ensure we're not messing with real data + assertDatabaseSecureAgainstBadSelection(); mServer = new MockWebServer(); mServer.play(); } @@ -188,34 +188,23 @@ public abstract class AbstractDownloadProviderFunctionalTest extends protected void startDownload(long id) { final JobParameters params = mock(JobParameters.class); when(params.getJobId()).thenReturn((int) id); + getService().onBind(null); getService().onStartJob(params); } - private boolean isDatabaseEmpty() { - Cursor cursor = mResolver.query(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, - null, null, null, null); - try { - return cursor.getCount() == 0; - } finally { - cursor.close(); + private void assertDatabaseEmpty() { + try (Cursor cursor = mResolver.query(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, + null, null, null, null)) { + assertEquals(0, cursor.getCount()); } } - private boolean isDatabaseSecureAgainstBadSelection() { - Cursor cursor = null; - try { - cursor = mResolver.query(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, null, - "('1'='1'))) ORDER BY lastmod DESC--", null, null); + private void assertDatabaseSecureAgainstBadSelection() { + try (Cursor cursor = mResolver.query(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, null, + "('1'='1'))) ORDER BY lastmod DESC--", null, null)) { + fail("Database isn't secure!"); + } catch (Exception expected) { } - catch (Exception e) { - return true; - } finally { - if (cursor != null) { - cursor.close(); - } - } - - return false; } /** -- cgit v1.2.3