use of android.app.DownloadManager.Query in project platform_frameworks_base by android.
the class DownloadManagerBaseTest method getBytesDownloaded.
private long getBytesDownloaded(long id) {
DownloadManager.Query q = new DownloadManager.Query();
q.setFilterById(id);
Cursor response = mDownloadManager.query(q);
if (response.getCount() < 1) {
Log.i(LOG_TAG, String.format("Query to download manager returned nothing for id %d", id));
response.close();
return -1;
}
while (response.moveToNext()) {
int index = response.getColumnIndex(DownloadManager.COLUMN_ID);
if (id == response.getLong(index)) {
break;
}
}
int index = response.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR);
if (index < 0) {
Log.i(LOG_TAG, String.format("No downloaded bytes for id %d", id));
response.close();
return -1;
}
long size = response.getLong(index);
response.close();
return size;
}
use of android.app.DownloadManager.Query in project android_frameworks_base by DirtyUnicorns.
the class DownloadManagerFunctionalTest method testRemoveDownload.
/**
* Tests that we can remove a download from the download manager.
*/
@LargeTest
public void testRemoveDownload() throws Exception {
int fileSize = 1024;
byte[] blobData = generateData(fileSize, DataType.BINARY);
long dlRequest = doBasicDownload(blobData, DOWNLOAD_TO_DOWNLOAD_CACHE_DIR);
Cursor cursor = mDownloadManager.query(new Query().setFilterById(dlRequest));
try {
assertEquals("The count of downloads with this ID is not 1!", 1, cursor.getCount());
mDownloadManager.remove(dlRequest);
cursor.requery();
assertEquals("The count of downloads with this ID is not 0!", 0, cursor.getCount());
} finally {
cursor.close();
}
}
use of android.app.DownloadManager.Query in project android_frameworks_base by DirtyUnicorns.
the class DownloadManagerBaseTest method removeAllCurrentDownloads.
/**
* Helper to remove all downloads that are registered with the DL Manager.
*
* Note: This gives us a clean slate b/c it includes downloads that are pending, running,
* paused, or have completed.
*/
protected void removeAllCurrentDownloads() {
Log.i(LOG_TAG, "Removing all current registered downloads...");
Cursor cursor = mDownloadManager.query(new Query());
try {
if (cursor.moveToFirst()) {
do {
int index = cursor.getColumnIndex(DownloadManager.COLUMN_ID);
long downloadId = cursor.getLong(index);
mDownloadManager.remove(downloadId);
} while (cursor.moveToNext());
}
} finally {
cursor.close();
}
}
use of android.app.DownloadManager.Query in project android_frameworks_base by DirtyUnicorns.
the class DownloadManagerBaseTest method getBytesDownloaded.
private long getBytesDownloaded(long id) {
DownloadManager.Query q = new DownloadManager.Query();
q.setFilterById(id);
Cursor response = mDownloadManager.query(q);
if (response.getCount() < 1) {
Log.i(LOG_TAG, String.format("Query to download manager returned nothing for id %d", id));
response.close();
return -1;
}
while (response.moveToNext()) {
int index = response.getColumnIndex(DownloadManager.COLUMN_ID);
if (id == response.getLong(index)) {
break;
}
}
int index = response.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR);
if (index < 0) {
Log.i(LOG_TAG, String.format("No downloaded bytes for id %d", id));
response.close();
return -1;
}
long size = response.getLong(index);
response.close();
return size;
}
use of android.app.DownloadManager.Query in project android_frameworks_base by AOSPA.
the class ConnectionUtil method downloadSuccessful.
/**
* Determines if a given download was successful by querying the DownloadManager.
*
* @param enqueue the id used to identify/query the DownloadManager with.
* @return true if download was successful, false otherwise.
*/
private boolean downloadSuccessful(long enqueue) {
Query query = new Query();
query.setFilterById(enqueue);
Cursor c = mDownloadManager.query(query);
if (c.moveToFirst()) {
int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
Log.v(LOG_TAG, "Successfully downloaded file!");
return true;
}
}
return false;
}
Aggregations