question: private boolean updateLocked ( ) { boolean isActive = false ; long nextRetryTimeMillis = Long . MAX_VALUE ; long now = systemFacade . currentTimeMillis ( ) ; Collection < FileDownloadInfo > allDownloads = downloadsRepository . getAllDownloads ( ) ; updateTotalBytesFor ( allDownloads ) ; List < DownloadBatch > downloadBatches = batchRepository . retrieveBatchesFor ( allDownloads ) ; for ( DownloadBatch downloadBatch : downloadBatches ) { if ( downloadBatch . isActive ( ) ) { isActive = true ; break ; } } for ( DownloadBatch downloadBatch : downloadBatches ) { if ( downloadBatch . isDeleted ( ) || downloadBatch . prune ( downloadDeleter ) ) { continue ; } if ( ! isActive && downloadReadyChecker . canDownload ( downloadBatch ) ) { boolean isBatchStartingForTheFirstTime = batchRepository . isBatchStartingForTheFirstTime ( downloadBatch . getBatchId ( ) ) ; if ( isBatchStartingForTheFirstTime ) { handleBatchStartingForTheFirstTime ( downloadBatch ) ; } downloadOrContinueBatch ( downloadBatch . getDownloads ( ) ) ; isActive = true ; } else if ( downloadBatch . scanCompletedMediaIfReady ( downloadScanner ) ) { isActive = true ; } nextRetryTimeMillis = downloadBatch . nextActionMillis ( now , nextRetryTimeMillis ) ; } batchRepository . deleteMarkedBatchesFor ( allDownloads ) ; updateUserVisibleNotification ( downloadBatches ) ; if ( nextRetryTimeMillis > 0 && nextRetryTimeMillis < Long . MAX_VALUE ) { LLog . v ( "scheduling start in " + nextRetryTimeMillis + "ms" ) ; Intent intent = new Intent ( Constants . ACTION_RETRY ) ; intent . setClass ( this , DownloadReceiver . class ) ; alarmManager . set ( AlarmManager . RTC_WAKEUP , now + nextRetryTimeMillis , PendingIntent . getBroadcast ( this , 0 , intent , PendingIntent . FLAG_ONE_SHOT ) ) ; } if ( ! isActive ) { moveSubmittedTasksToBatchStatusIfNecessary ( ) ; } return isActive ; }
target:  Update {#downloads} to match {DownloadProvider} state. Depending on current download state it may enqueue {DownloadTask} instances, request {DownloadScanner} scans, update user-visible notifications, and/or schedule future actions with {AlarmManager}. <p/> Should only be called from {#updateThread} as after being requested through {#enqueueUpdate()}. for (DownloadInfo info : downloadBatch.getDownloads()) { if (info.isDeleted) { snapshot taken in this update.