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();
}
}
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);
}
}
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);
}
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();
}
}
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);
}
}
Aggregations