use of android.app.DownloadManager.Query in project android_frameworks_base by ResurrectionRemix.
the class DownloadManagerFunctionalTest method verifyDownload.
/**
* Helper to verify a standard single-file download from the mock server, and clean up after
* verification
*
* Note that this also calls the Download manager's remove, which cleans up the file from cache.
*
* @param requestId The id of the download to remove
* @param fileData The data to verify the file contains
*/
private void verifyDownload(long requestId, byte[] fileData) throws Exception {
int fileSize = fileData.length;
ParcelFileDescriptor pfd = mDownloadManager.openDownloadedFile(requestId);
Cursor cursor = mDownloadManager.query(new Query().setFilterById(requestId));
try {
assertEquals(1, cursor.getCount());
assertTrue(cursor.moveToFirst());
verifyFileSize(pfd, fileSize);
verifyFileContents(pfd, fileData);
assertTrue(new File(CACHE_DIR + "/" + DEFAULT_FILENAME).exists());
} finally {
pfd.close();
cursor.close();
}
}
use of android.app.DownloadManager.Query in project android_frameworks_base by ResurrectionRemix.
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 ResurrectionRemix.
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_packages_inputmethods_LatinIME by CyanogenMod.
the class UpdateHandler method getCompletedDownloadInfo.
/**
* Retrieve information about a specific download from DownloadManager.
*/
private static CompletedDownloadInfo getCompletedDownloadInfo(final DownloadManagerWrapper manager, final long downloadId) {
final Query query = new Query().setFilterById(downloadId);
final Cursor cursor = manager.query(query);
if (null == cursor) {
return new CompletedDownloadInfo(null, downloadId, DownloadManager.STATUS_FAILED);
}
try {
final String uri;
final int status;
if (cursor.moveToNext()) {
final int columnStatus = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
final int columnError = cursor.getColumnIndex(DownloadManager.COLUMN_REASON);
final int columnUri = cursor.getColumnIndex(DownloadManager.COLUMN_URI);
final int error = cursor.getInt(columnError);
status = cursor.getInt(columnStatus);
final String uriWithAnchor = cursor.getString(columnUri);
int anchorIndex = uriWithAnchor.indexOf('#');
if (anchorIndex != -1) {
uri = uriWithAnchor.substring(0, anchorIndex);
} else {
uri = uriWithAnchor;
}
if (DownloadManager.STATUS_SUCCESSFUL != status) {
Log.e(TAG, "Permanent failure of download " + downloadId + " with error code: " + error);
}
} else {
uri = null;
status = DownloadManager.STATUS_FAILED;
}
return new CompletedDownloadInfo(uri, downloadId, status);
} finally {
cursor.close();
}
}
use of android.app.DownloadManager.Query in project android_frameworks_base by crdroidandroid.
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