use of android.app.DownloadManager.Request in project android_frameworks_base by ParanoidAndroid.
the class DownloadManagerTestApp method runDownloadMultipleSwitching.
/**
* Tests that downloads resume when switching back and forth from having connectivity to
* having no connectivity using both WiFi and airplane mode.
*
* Note: Device has no mobile access when running this test.
*
* @throws Exception if unsuccessful
*/
public void runDownloadMultipleSwitching() throws Exception {
String filename = DOWNLOAD_5MB_FILENAME;
long filesize = DOWNLOAD_5MB_FILESIZE;
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_MOBILE | Request.NETWORK_WIFI);
dlRequest = mDownloadManager.enqueue(request);
waitForDownloadToStart(dlRequest);
// make sure we're starting to download some data...
waitForFileToGrow(downloadedFile);
// download disable
setWiFiStateOn(false);
// download disable
Log.i(LOG_TAG, "Turning on airplane mode...");
setAirplaneModeOn(true);
// wait 30 secs
Thread.sleep(30 * 1000);
// download disable
setWiFiStateOn(true);
// wait 30 secs
Thread.sleep(30 * 1000);
// download enable
Log.i(LOG_TAG, "Turning off airplane mode...");
setAirplaneModeOn(false);
// wait 5 seconds
Thread.sleep(5 * 1000);
// download disable
Log.i(LOG_TAG, "Turning off WiFi...");
setWiFiStateOn(false);
// wait 30 secs
Thread.sleep(30 * 1000);
// finally, turn WiFi back on and finish up the download
Log.i(LOG_TAG, "Turning on WiFi...");
setWiFiStateOn(true);
Log.i(LOG_TAG, "Waiting up to 3 minutes for download to complete...");
waitForDownloadsOrTimeout(dlRequest, 3 * 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();
}
}
use of android.app.DownloadManager.Request in project android_frameworks_base by ParanoidAndroid.
the class DownloadManagerTestApp method runDownloadMultipleSimultaneously.
/**
* Tests 15 concurrent downloads of 1,000,000-byte files.
*
* @throws Exception if test failed
*/
public void runDownloadMultipleSimultaneously() throws Exception {
final int TOTAL_DOWNLOADS = 15;
HashSet<Long> downloadIds = new HashSet<Long>(TOTAL_DOWNLOADS);
MultipleDownloadsCompletedReceiver receiver = registerNewMultipleDownloadsReceiver();
// Make sure there are no pending downloads currently going on
removeAllCurrentDownloads();
try {
for (int i = 0; i < TOTAL_DOWNLOADS; ++i) {
long dlRequest = -1;
String filename = FILE_CONCURRENT_DOWNLOAD_FILE_PREFIX + i + FILE_CONCURRENT_DOWNLOAD_FILE_EXTENSION;
Uri remoteUri = getExternalFileUri(filename);
Request request = new Request(remoteUri);
request.setTitle(filename);
dlRequest = mDownloadManager.enqueue(request);
assertTrue(dlRequest != -1);
downloadIds.add(dlRequest);
}
// wait 15 mins max
waitForDownloadsOrTimeout(DEFAULT_WAIT_POLL_TIME, 15 * 60 * 2000);
assertEquals(TOTAL_DOWNLOADS, receiver.numDownloadsCompleted());
} finally {
removeAllCurrentDownloads();
}
}
use of android.app.DownloadManager.Request in project android_frameworks_base by ParanoidAndroid.
the class DownloadManagerTestApp method runDownloadMultipleWiFiEnableDisable.
/**
* Tests that downloads resume when switching on/off WiFi at various intervals.
*
* Note: Device has no mobile access when running this test.
*
* @throws Exception if unsuccessful
*/
public void runDownloadMultipleWiFiEnableDisable() throws Exception {
String filename = DOWNLOAD_5MB_FILENAME;
long filesize = DOWNLOAD_5MB_FILESIZE;
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?
waitForFileToGrow(downloadedFile);
// download disable
Log.i(LOG_TAG, "Turning off WiFi...");
setWiFiStateOn(false);
// wait 40 seconds
Thread.sleep(40 * 1000);
// enable download...
Log.i(LOG_TAG, "Turning on WiFi again...");
setWiFiStateOn(true);
waitForFileToGrow(downloadedFile);
// download disable
Log.i(LOG_TAG, "Turning off WiFi...");
setWiFiStateOn(false);
// wait 20 seconds
Thread.sleep(20 * 1000);
// enable download...
Log.i(LOG_TAG, "Turning on WiFi again...");
setWiFiStateOn(true);
Log.i(LOG_TAG, "Waiting up to 3 minutes for download to complete...");
waitForDownloadsOrTimeout(dlRequest, 3 * 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();
}
}
use of android.app.DownloadManager.Request in project android_frameworks_base by ResurrectionRemix.
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 ResurrectionRemix.
the class DownloadManagerFunctionalTest method testDownloadToExternal_fileExists.
/**
* Tests trying to download to SD card when the file with same name already exists.
*/
@LargeTest
public void testDownloadToExternal_fileExists() throws Exception {
File existentFile = createFileOnSD(null, 1, DataType.TEXT, null);
byte[] blobData = generateData(DEFAULT_FILE_SIZE, DataType.TEXT);
// Prepare the mock server with a standard response
enqueueResponse(buildResponse(HTTP_OK, blobData));
try {
Uri uri = getServerUri(DEFAULT_FILENAME);
Request request = new Request(uri);
Uri localUri = Uri.fromFile(existentFile);
request.setDestinationUri(localUri);
long dlRequest = mDownloadManager.enqueue(request);
// wait for the download to complete
waitForDownloadOrTimeout(dlRequest);
Cursor cursor = getCursor(dlRequest);
try {
verifyInt(cursor, DownloadManager.COLUMN_STATUS, DownloadManager.STATUS_SUCCESSFUL);
} finally {
cursor.close();
}
} finally {
existentFile.delete();
}
}
Aggregations