use of android.app.DownloadManager.Request in project android_frameworks_base by ResurrectionRemix.
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());
}
use of android.app.DownloadManager.Request in project android_frameworks_base by ResurrectionRemix.
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 android_frameworks_base by ResurrectionRemix.
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 android_frameworks_base by ResurrectionRemix.
the class DownloadManagerFunctionalTest method testSetTitle.
/**
* Tests that we can set the title of a download.
*/
@LargeTest
public void testSetTitle() throws Exception {
int fileSize = 1024;
byte[] blobData = generateData(fileSize, DataType.BINARY);
enqueueResponse(buildResponse(HTTP_OK, blobData));
// An arbitrary unicode string title
final String title = "¥123;\"ŒŽ Ջ ਇ 쳠 栠Ψ尴" + "ඩ샅솨 #\'";
Uri uri = getServerUri(DEFAULT_FILENAME);
Request request = new Request(uri);
request.setTitle(title);
long dlRequest = mDownloadManager.enqueue(request);
waitForDownloadOrTimeout(dlRequest);
Cursor cursor = getCursor(dlRequest);
try {
verifyString(cursor, DownloadManager.COLUMN_TITLE, title);
} finally {
cursor.close();
}
}
use of android.app.DownloadManager.Request in project android_frameworks_base by ResurrectionRemix.
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();
}
}
Aggregations