Search in sources :

Example 31 with Request

use of android.app.DownloadManager.Request in project android_frameworks_base by AOSPA.

the class DownloadManagerFunctionalTest method testDownloadToProhibitedDirectory.

/**
     * Tests trying to download a file to the system partition.
     */
@LargeTest
public void testDownloadToProhibitedDirectory() throws Exception {
    File downloadedFile = new File(PROHIBITED_DIRECTORY, DEFAULT_FILENAME);
    try {
        byte[] blobData = generateData(DEFAULT_FILE_SIZE, DataType.TEXT);
        // Prepare the mock server with a standard response
        enqueueResponse(buildResponse(HTTP_OK, blobData));
        Uri uri = getServerUri(DEFAULT_FILENAME);
        Request request = new Request(uri);
        Uri localUri = Uri.fromFile(downloadedFile);
        request.setDestinationUri(localUri);
        try {
            mDownloadManager.enqueue(request);
            fail("Failed to throw SecurityException when trying to write to /system.");
        } catch (SecurityException s) {
            assertFalse(downloadedFile.exists());
        }
    } finally {
        // Just in case file somehow got created, make sure to delete it
        downloadedFile.delete();
    }
}
Also used : Request(android.app.DownloadManager.Request) File(java.io.File) Uri(android.net.Uri) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 32 with Request

use of android.app.DownloadManager.Request in project android_frameworks_base by AOSPA.

the class DownloadManagerFunctionalTest method testDownloadNoWifi.

/**
     * Tests that a download set for Wifi does not progress while Wifi is disabled, but resumes
     * once Wifi is re-enabled.
     */
@LargeTest
public void testDownloadNoWifi() throws Exception {
    // wait only 60 seconds before giving up
    long timeout = 60 * 1000;
    // 140k
    int fileSize = 1024;
    byte[] blobData = generateData(fileSize, DataType.TEXT);
    setWiFiStateOn(false);
    enqueueResponse(buildResponse(HTTP_OK, blobData));
    try {
        Uri uri = getServerUri(DEFAULT_FILENAME);
        Request request = new Request(uri);
        request.setAllowedNetworkTypes(Request.NETWORK_WIFI);
        long dlRequest = mDownloadManager.enqueue(request);
        // wait for the download to complete
        boolean success = waitForDownloadOrTimeoutNoThrow(dlRequest, WAIT_FOR_DOWNLOAD_POLL_TIME, timeout);
        assertFalse("Download proceeded without Wifi connection!", success);
        setWiFiStateOn(true);
        waitForDownloadOrTimeout(dlRequest);
        assertEquals(1, mReceiver.numDownloadsCompleted());
    } finally {
        setWiFiStateOn(true);
    }
}
Also used : Request(android.app.DownloadManager.Request) Uri(android.net.Uri) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 33 with Request

use of android.app.DownloadManager.Request in project platform_frameworks_base by android.

the class DownloadManagerBaseTest method doEnqueue.

private long doEnqueue(int location) throws Exception {
    Uri uri = getServerUri(DEFAULT_FILENAME);
    Request request = new Request(uri).setTitle(DEFAULT_FILENAME);
    if (location == DOWNLOAD_TO_SYSTEM_CACHE) {
        request.setDestinationToSystemCache();
    }
    return mDownloadManager.enqueue(request);
}
Also used : Request(android.app.DownloadManager.Request) Uri(android.net.Uri)

Example 34 with Request

use of android.app.DownloadManager.Request in project platform_frameworks_base by android.

the class DownloadManagerFunctionalTest method testDownloadToExternal.

/**
     * Tests trying to download a file to SD card.
     */
@LargeTest
public void testDownloadToExternal() throws Exception {
    String localDownloadDirectory = Environment.getExternalStorageDirectory().getPath();
    File downloadedFile = new File(localDownloadDirectory, DEFAULT_FILENAME);
    // make sure the file doesn't already exist in the directory
    downloadedFile.delete();
    try {
        byte[] blobData = generateData(DEFAULT_FILE_SIZE, DataType.TEXT);
        // Prepare the mock server with a standard response
        enqueueResponse(buildResponse(HTTP_OK, blobData));
        Uri uri = getServerUri(DEFAULT_FILENAME);
        Request request = new Request(uri);
        Uri localUri = Uri.fromFile(downloadedFile);
        request.setDestinationUri(localUri);
        long dlRequest = mDownloadManager.enqueue(request);
        // wait for the download to complete
        waitForDownloadOrTimeout(dlRequest);
        verifyAndCleanupSingleFileDownload(dlRequest, blobData);
        assertEquals(1, mReceiver.numDownloadsCompleted());
    } finally {
        downloadedFile.delete();
    }
}
Also used : Request(android.app.DownloadManager.Request) File(java.io.File) Uri(android.net.Uri) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 35 with Request

use of android.app.DownloadManager.Request in project platform_frameworks_base by android.

the class DownloadManagerFunctionalTest method testDownloadNoWifi.

/**
     * Tests that a download set for Wifi does not progress while Wifi is disabled, but resumes
     * once Wifi is re-enabled.
     */
@LargeTest
public void testDownloadNoWifi() throws Exception {
    // wait only 60 seconds before giving up
    long timeout = 60 * 1000;
    // 140k
    int fileSize = 1024;
    byte[] blobData = generateData(fileSize, DataType.TEXT);
    setWiFiStateOn(false);
    enqueueResponse(buildResponse(HTTP_OK, blobData));
    try {
        Uri uri = getServerUri(DEFAULT_FILENAME);
        Request request = new Request(uri);
        request.setAllowedNetworkTypes(Request.NETWORK_WIFI);
        long dlRequest = mDownloadManager.enqueue(request);
        // wait for the download to complete
        boolean success = waitForDownloadOrTimeoutNoThrow(dlRequest, WAIT_FOR_DOWNLOAD_POLL_TIME, timeout);
        assertFalse("Download proceeded without Wifi connection!", success);
        setWiFiStateOn(true);
        waitForDownloadOrTimeout(dlRequest);
        assertEquals(1, mReceiver.numDownloadsCompleted());
    } finally {
        setWiFiStateOn(true);
    }
}
Also used : Request(android.app.DownloadManager.Request) Uri(android.net.Uri) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

Request (android.app.DownloadManager.Request)122 Uri (android.net.Uri)86 LargeTest (android.test.suitebuilder.annotation.LargeTest)41 File (java.io.File)38 Cursor (android.database.Cursor)32 ParcelFileDescriptor (android.os.ParcelFileDescriptor)24 DownloadManager (android.app.DownloadManager)17 Suppress (android.test.suitebuilder.annotation.Suppress)10 Query (android.app.DownloadManager.Query)6 DataOutputStream (java.io.DataOutputStream)6 FileOutputStream (java.io.FileOutputStream)6 HashSet (java.util.HashSet)6 Random (java.util.Random)6 Resources (android.content.res.Resources)5 UiObject (android.support.test.uiautomator.UiObject)5 MockResponse (com.google.mockwebserver.MockResponse)4 TimeoutException (java.util.concurrent.TimeoutException)4 AlertDialog (android.app.AlertDialog)3 Context (android.content.Context)3 DialogInterface (android.content.DialogInterface)3