use of android.app.DownloadManager.Query in project android_frameworks_base by ParanoidAndroid.
the class DownloadManagerBaseTest method verifyAndCleanupSingleFileDownload.
/**
* 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
*/
protected void verifyAndCleanupSingleFileDownload(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);
} finally {
pfd.close();
cursor.close();
mDownloadManager.remove(requestId);
}
}
use of android.app.DownloadManager.Query in project android_frameworks_base by ParanoidAndroid.
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 Xposed-Tinted-Status-Bar by MohammadAG.
the class DownloadsUtil method getAllForUrl.
public static List<DownloadInfo> getAllForUrl(Context context, String url) {
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Cursor c = dm.query(new Query());
int columnId = c.getColumnIndexOrThrow(DownloadManager.COLUMN_ID);
int columnUri = c.getColumnIndexOrThrow(DownloadManager.COLUMN_URI);
int columnTitle = c.getColumnIndexOrThrow(DownloadManager.COLUMN_TITLE);
int columnLastMod = c.getColumnIndexOrThrow(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP);
int columnFilename = c.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_FILENAME);
int columnStatus = c.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS);
int columnTotalSize = c.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES);
int columnBytesDownloaded = c.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR);
int columnReason = c.getColumnIndexOrThrow(DownloadManager.COLUMN_REASON);
List<DownloadInfo> downloads = new ArrayList<DownloadInfo>();
while (c.moveToNext()) {
if (!url.equals(c.getString(columnUri)))
continue;
String localFilename = c.getString(columnFilename);
if (localFilename != null && !localFilename.isEmpty() && !new File(localFilename).isFile()) {
dm.remove(c.getLong(columnId));
continue;
}
downloads.add(new DownloadInfo(c.getLong(columnId), c.getString(columnUri), c.getString(columnTitle), c.getLong(columnLastMod), localFilename, c.getInt(columnStatus), c.getInt(columnTotalSize), c.getInt(columnBytesDownloaded), c.getInt(columnReason)));
}
Collections.sort(downloads);
return downloads;
}
use of android.app.DownloadManager.Query in project XposedInstaller by rovo89.
the class DownloadsUtil method getAllForUrl.
public static List<DownloadInfo> getAllForUrl(Context context, String url) {
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Cursor c = dm.query(new Query());
int columnId = c.getColumnIndexOrThrow(DownloadManager.COLUMN_ID);
int columnUri = c.getColumnIndexOrThrow(DownloadManager.COLUMN_URI);
int columnTitle = c.getColumnIndexOrThrow(DownloadManager.COLUMN_TITLE);
int columnLastMod = c.getColumnIndexOrThrow(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP);
int columnFilename = c.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_FILENAME);
int columnStatus = c.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS);
int columnTotalSize = c.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES);
int columnBytesDownloaded = c.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR);
int columnReason = c.getColumnIndexOrThrow(DownloadManager.COLUMN_REASON);
List<DownloadInfo> downloads = new ArrayList<>();
while (c.moveToNext()) {
if (!url.equals(c.getString(columnUri)))
continue;
int status = c.getInt(columnStatus);
String localFilename = c.getString(columnFilename);
if (status == DownloadManager.STATUS_SUCCESSFUL && !new File(localFilename).isFile()) {
dm.remove(c.getLong(columnId));
continue;
}
downloads.add(new DownloadInfo(c.getLong(columnId), c.getString(columnUri), c.getString(columnTitle), c.getLong(columnLastMod), localFilename, status, c.getInt(columnTotalSize), c.getInt(columnBytesDownloaded), c.getInt(columnReason)));
}
c.close();
Collections.sort(downloads);
return downloads;
}
use of android.app.DownloadManager.Query in project XposedInstaller by rovo89.
the class DownloadsUtil method removeAllForLocalFile.
public static void removeAllForLocalFile(Context context, File file) {
file.delete();
String filename;
try {
filename = file.getCanonicalPath();
} catch (IOException e) {
Log.w(XposedApp.TAG, "Could not resolve path for " + file.getAbsolutePath(), e);
return;
}
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Cursor c = dm.query(new Query());
int columnId = c.getColumnIndexOrThrow(DownloadManager.COLUMN_ID);
int columnFilename = c.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_FILENAME);
List<Long> idsList = new ArrayList<>(1);
while (c.moveToNext()) {
String itemFilename = c.getString(columnFilename);
if (itemFilename != null) {
if (filename.equals(itemFilename)) {
idsList.add(c.getLong(columnId));
} else {
try {
if (filename.equals(new File(itemFilename).getCanonicalPath())) {
idsList.add(c.getLong(columnId));
}
} catch (IOException ignored) {
}
}
}
}
c.close();
if (idsList.isEmpty())
return;
long[] ids = new long[idsList.size()];
for (int i = 0; i < ids.length; i++) ids[i] = idsList.get(i);
dm.remove(ids);
}
Aggregations