private long discardPurgeableFiles(int destination,long targetBytes){
  LLog.i("discardPurgeableFiles: destination = " + destination + ", targetBytes = "+ targetBytes);
  String destStr=(destination == DownloadsDestination.DESTINATION_SYSTEMCACHE_PARTITION) ? String.valueOf(destination) : String.valueOf(DownloadsDestination.DESTINATION_CACHE_PARTITION_PURGEABLE);
  String[] bindArgs=new String[]{destStr};
  Cursor cursor=contentResolver.query(downloadsUriProvider.getAllDownloadsUri(),null,"( " + DownloadContract.Downloads.COLUMN_STATUS + " = '"+ DownloadStatus.SUCCESS+ "' AND "+ DownloadContract.Downloads.COLUMN_DESTINATION+ " = ? )",bindArgs,DownloadContract.Downloads.COLUMN_LAST_MODIFICATION);
  if (cursor == null) {
    return 0;
  }
  long totalFreed=0;
  try {
    final int dataIndex=cursor.getColumnIndex(DownloadContract.Downloads.COLUMN_DATA);
    while (cursor.moveToNext() && totalFreed < targetBytes) {
      final String data=cursor.getString(dataIndex);
      if (TextUtils.isEmpty(data))       continue;
      File file=new File(data);
      LLog.d("purging " + file.getAbsolutePath() + " for "+ file.length()+ " bytes");
      totalFreed+=file.length();
      file.delete();
      long id=cursor.getLong(cursor.getColumnIndex(DownloadContract.Downloads._ID));
      contentResolver.delete(ContentUris.withAppendedId(downloadsUriProvider.getAllDownloadsUri(),id),null,null);
    }
  }
  finally {
    cursor.close();
  }
  LLog.i("Purged files, freed " + totalFreed + " for "+ targetBytes+ " requested");
  return totalFreed;
}

private long discardPurgeableFiles ( int destination , long targetBytes ) { LLog . i ( "discardPurgeableFiles: destination = " + destination + ", targetBytes = " + targetBytes ) ; String destStr = ( destination == DownloadsDestination . DESTINATION_SYSTEMCACHE_PARTITION ) ? String . valueOf ( destination ) : String . valueOf ( DownloadsDestination . DESTINATION_CACHE_PARTITION_PURGEABLE ) ; String [ ] bindArgs = new String [ ] { destStr } ; Cursor cursor = contentResolver . query ( downloadsUriProvider . getAllDownloadsUri ( ) , null , "( " + DownloadContract . Downloads . COLUMN_STATUS + " = '" + DownloadStatus . SUCCESS + "' AND " + DownloadContract . Downloads . COLUMN_DESTINATION + " = ? )" , bindArgs , DownloadContract . Downloads . COLUMN_LAST_MODIFICATION ) ; if ( cursor == null ) { return 0 ; } long totalFreed = 0 ; try { final int dataIndex = cursor . getColumnIndex ( DownloadContract . Downloads . COLUMN_DATA ) ; while ( cursor . moveToNext ( ) && totalFreed < targetBytes ) { final String data = cursor . getString ( dataIndex ) ; if ( TextUtils . isEmpty ( data ) ) continue ; File file = new File ( data ) ; LLog . d ( "purging " + file . getAbsolutePath ( ) + " for " + file . length ( ) + " bytes" ) ; totalFreed += file . length ( ) ; file . delete ( ) ; long id = cursor . getLong ( cursor . getColumnIndex ( DownloadContract . Downloads . _ID ) ) ; contentResolver . delete ( ContentUris . withAppendedId ( downloadsUriProvider . getAllDownloadsUri ( ) , id ) , null , null ) ; } } finally { cursor . close ( ) ; } LLog . i ( "Purged files, freed " + totalFreed + " for " + targetBytes + " requested" ) ; return totalFreed ; }
deletes purgeable files from the cache partition . this also deletes the matching database entries . files are deleted in lru order until the total byte size is greater than targetbytes
