Search in sources :

Example 86 with Request

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

the class FilesActivityUiTest method testDownload_Queued.

// We don't really need to test the entirety of download support
// since downloads is (almost) just another provider.
@Suppress
public void testDownload_Queued() throws Exception {
    DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    // This downloads ends up being queued (because DNS can't be resolved).
    // We'll still see an entry in the downloads UI with a "Queued" label.
    dm.enqueue(new Request(Uri.parse("http://hammychamp.toodles")));
    bots.roots.openRoot("Downloads");
    bots.directory.assertDocumentsPresent("Queued");
}
Also used : Request(android.app.DownloadManager.Request) DownloadManager(android.app.DownloadManager) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 87 with Request

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

the class FilesActivityUiTest method testDownload_RetryUnsuccessful.

@Suppress
public void testDownload_RetryUnsuccessful() throws Exception {
    DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    // This downloads fails! But it'll still show up.
    dm.enqueue(new Request(Uri.parse("http://www.google.com/hamfancy")));
    bots.roots.openRoot("Downloads");
    UiObject doc = bots.directory.findDocument("Unsuccessful");
    doc.waitForExists(TIMEOUT);
    int toolType = Configurator.getInstance().getToolType();
    Configurator.getInstance().setToolType(MotionEvent.TOOL_TYPE_FINGER);
    doc.click();
    Configurator.getInstance().setToolType(toolType);
    assertTrue(bots.main.findDownloadRetryDialog().exists());
    // to clear the dialog.
    device.pressBack();
}
Also used : UiObject(android.support.test.uiautomator.UiObject) Request(android.app.DownloadManager.Request) DownloadManager(android.app.DownloadManager) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 88 with Request

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

the class ConnectionUtil method startDownloadAndWait.

/**
     * Start a download on a given url and wait for completion.
     *
     * @param targetUrl the target to download.x
     * @param timeout to wait for download to finish
     * @return true if we successfully downloaded the requestedUrl, false otherwise.
     */
public boolean startDownloadAndWait(String targetUrl, long timeout) {
    if (targetUrl.length() == 0 || targetUrl == null) {
        Log.v(LOG_TAG, "Empty or Null target url requested to DownloadManager");
        return true;
    }
    Request request = new Request(Uri.parse(targetUrl));
    long enqueue = mDownloadManager.enqueue(request);
    Log.v(LOG_TAG, "Sending download request of " + targetUrl + " to DownloadManager");
    long startTime = System.currentTimeMillis();
    while (true) {
        if ((System.currentTimeMillis() - startTime) > timeout) {
            Log.v(LOG_TAG, "startDownloadAndWait timed out, failed to fetch " + targetUrl + " within " + timeout);
            return downloadSuccessful(enqueue);
        }
        Log.v(LOG_TAG, "Waiting for the download to finish " + targetUrl);
        synchronized (mDownloadMonitor) {
            try {
                mDownloadMonitor.wait(SHORT_TIMEOUT);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (!downloadSuccessful(enqueue)) {
                continue;
            }
            return true;
        }
    }
}
Also used : Request(android.app.DownloadManager.Request)

Example 89 with Request

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

the class DownloadManagerTestApp method runDownloadMultipleAirplaneModeEnableDisable.

/**
     * Tests that downloads resume when switching on/off Airplane mode numerous times at
     * various intervals.
     *
     * Note: Device has no mobile access when running this test.
     *
     * @throws Exception if unsuccessful
     */
public void runDownloadMultipleAirplaneModeEnableDisable() throws Exception {
    String filename = DOWNLOAD_FILENAME;
    long filesize = DOWNLOAD_FILESIZE;
    // make sure WiFi is enabled, and airplane mode is not on
    doCommonDownloadSetup();
    String localDownloadDirectory = Environment.getExternalStorageDirectory().getPath();
    File downloadedFile = new File(localDownloadDirectory, filename);
    long dlRequest = -1;
    try {
        downloadedFile.delete();
        // Make sure there are no pending downloads currently going on
        removeAllCurrentDownloads();
        Uri remoteUri = getExternalFileUri(filename);
        Request request = new Request(remoteUri);
        // Local destination of downloaded file
        Uri localUri = Uri.fromFile(downloadedFile);
        Log.i(LOG_TAG, "setting localUri to: " + localUri.getPath());
        request.setDestinationUri(localUri);
        request.setAllowedNetworkTypes(Request.NETWORK_WIFI);
        dlRequest = mDownloadManager.enqueue(request);
        waitForDownloadToStart(dlRequest);
        // are we making any progress?
        waitToReceiveData(dlRequest, EXPECTED_PROGRESS);
        // download disable
        Log.i(LOG_TAG, "Turning on Airplane mode...");
        setAirplaneModeOn(true);
        // wait 1 minute
        Thread.sleep(60 * 1000);
        // download enable
        Log.i(LOG_TAG, "Turning off Airplane mode...");
        setAirplaneModeOn(false);
        // make sure we're starting to download some data...
        waitToReceiveData(dlRequest, EXPECTED_PROGRESS);
        // reenable the connection to start up the download again
        Log.i(LOG_TAG, "Turning on Airplane mode again...");
        setAirplaneModeOn(true);
        // wait 20 seconds
        Thread.sleep(20 * 1000);
        // Finish up the download...
        Log.i(LOG_TAG, "Turning off Airplane mode again...");
        setAirplaneModeOn(false);
        Log.i(LOG_TAG, "Waiting up to 10 minutes for donwload to complete...");
        // wait up to 10 mins
        assertTrue("download not finished", waitForDownload(dlRequest, 10 * 60 * 1000));
        ParcelFileDescriptor pfd = mDownloadManager.openDownloadedFile(dlRequest);
        verifyFileSize(pfd, filesize);
    } finally {
        Log.i(LOG_TAG, "Cleaning up files...");
        if (dlRequest != -1) {
            mDownloadManager.remove(dlRequest);
        }
        downloadedFile.delete();
    }
}
Also used : Request(android.app.DownloadManager.Request) ParcelFileDescriptor(android.os.ParcelFileDescriptor) File(java.io.File) Uri(android.net.Uri)

Example 90 with Request

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

the class DownloadManagerFunctionalTest method doErrorTest.

/**
     * Verifies a particular error code was received from a download
     *
     * @param uri The uri to enqueue to the DownloadManager
     * @param error The error code expected
     * @throws Exception if the test fails
     */
public void doErrorTest(Uri uri, int error) throws Exception {
    Request request = new Request(uri);
    request.setTitle(DEFAULT_FILENAME);
    long dlRequest = mDownloadManager.enqueue(request);
    try {
        waitForDownloadOrTimeout(dlRequest);
    } catch (TimeoutException ex) {
    // it is expected to timeout as download never finishes
    }
    Cursor cursor = getCursor(dlRequest);
    try {
        verifyInt(cursor, DownloadManager.COLUMN_REASON, error);
    } finally {
        cursor.close();
    }
}
Also used : Request(android.app.DownloadManager.Request) Cursor(android.database.Cursor) TimeoutException(java.util.concurrent.TimeoutException)

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