use of android.app.DownloadManager.Request in project platform_frameworks_base by android.
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;
}
}
}
use of android.app.DownloadManager.Request in project android_frameworks_base by crdroidandroid.
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;
}
}
}
use of android.app.DownloadManager.Request in project android_frameworks_base by crdroidandroid.
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");
}
use of android.app.DownloadManager.Request in project android_frameworks_base by crdroidandroid.
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();
}
use of android.app.DownloadManager.Request in project android_frameworks_base by crdroidandroid.
the class DownloadManagerFunctionalTest method testRelativeRedirect.
/**
* Tests the download failure error from an unhandled HTTP status code
*/
@LargeTest
public void testRelativeRedirect() throws Exception {
Uri uri = getServerUri(DEFAULT_FILENAME);
final MockResponse resp = buildResponse(HTTP_REDIRECT);
resp.setHeader("Location", ":" + uri.getSchemeSpecificPart());
enqueueResponse(resp);
byte[] blobData = generateData(DEFAULT_FILE_SIZE, DataType.TEXT);
enqueueResponse(buildResponse(HTTP_OK, blobData));
Request request = new Request(uri);
request.setTitle(DEFAULT_FILENAME);
long dlRequest = mDownloadManager.enqueue(request);
waitForDownloadOrTimeout(dlRequest);
verifyAndCleanupSingleFileDownload(dlRequest, blobData);
assertEquals(1, mReceiver.numDownloadsCompleted());
}
Aggregations