private void trimDatabase(){
  LLog.i("in trimDatabase");
  Cursor cursor=null;
  try {
    cursor=contentResolver.query(downloadsUriProvider.getAllDownloadsUri(),new String[]{DownloadContract.Downloads._ID},DownloadContract.Downloads.COLUMN_STATUS + " >= '200'",null,DownloadContract.Downloads.COLUMN_LAST_MODIFICATION);
    if (cursor == null) {
      LLog.e("null cursor in trimDatabase");
      return;
    }
    if (cursor.moveToFirst()) {
      int numDelete=cursor.getCount() - Constants.MAX_DOWNLOADS;
      int columnId=cursor.getColumnIndexOrThrow(DownloadContract.Downloads._ID);
      while (numDelete > 0) {
        Uri downloadUri=ContentUris.withAppendedId(downloadsUriProvider.getAllDownloadsUri(),cursor.getLong(columnId));
        contentResolver.delete(downloadUri,null,null);
        if (!cursor.moveToNext()) {
          break;
        }
        numDelete--;
      }
    }
  }
 catch (  SQLiteException e) {
    LLog.w("trimDatabase failed with exception: " + e.getMessage());
    return;
  }
 finally {
    if (cursor != null) {
      cursor.close();
    }
  }
}

private void trimDatabase ( ) { LLog . i ( "in trimDatabase" ) ; Cursor cursor = null ; try { cursor = contentResolver . query ( downloadsUriProvider . getAllDownloadsUri ( ) , new String [ ] { DownloadContract . Downloads . _ID } , DownloadContract . Downloads . COLUMN_STATUS + " >= '200'" , null , DownloadContract . Downloads . COLUMN_LAST_MODIFICATION ) ; if ( cursor == null ) { LLog . e ( "null cursor in trimDatabase" ) ; return ; } if ( cursor . moveToFirst ( ) ) { int numDelete = cursor . getCount ( ) - Constants . MAX_DOWNLOADS ; int columnId = cursor . getColumnIndexOrThrow ( DownloadContract . Downloads . _ID ) ; while ( numDelete > 0 ) { Uri downloadUri = ContentUris . withAppendedId ( downloadsUriProvider . getAllDownloadsUri ( ) , cursor . getLong ( columnId ) ) ; contentResolver . delete ( downloadUri , null , null ) ; if ( ! cursor . moveToNext ( ) ) { break ; } numDelete -- ; } } } catch ( SQLiteException e ) { LLog . w ( "trimDatabase failed with exception: " + e . getMessage ( ) ) ; return ; } finally { if ( cursor != null ) { cursor . close ( ) ; } } }
drops old rows from the database to prevent it from growing too large todo logic in this method needs to be optimized . maintain the number of downloads in memory - so that this method can limit the amount of data read .
