@Test public void mergeRequest_removing_becomesRestarting() { DownloadRequest downloadRequest = createDownloadRequest(); DownloadBuilder downloadBuilder = new DownloadBuilder(downloadRequest).setState(Download.STATE_REMOVING); Download download = downloadBuilder.build(); Download mergedDownload = DownloadManager.mergeRequest(download, downloadRequest, download.stopReason, NOW_MS); Download expectedDownload = downloadBuilder.setStartTimeMs(NOW_MS).setState(Download.STATE_RESTARTING).build(); assertEqualIgnoringUpdateTime(mergedDownload, expectedDownload); }
static Download mergeRequest( Download download, DownloadRequest request, int stopReason, long nowMs) { @Download.State int state = download.state; long startTimeMs = state == STATE_REMOVING || download.isTerminalState() ? nowMs : download.startTimeMs; if (state == STATE_REMOVING || state == STATE_RESTARTING) { state = STATE_RESTARTING; } else if (stopReason != STOP_REASON_NONE) { state = STATE_STOPPED; } else { state = STATE_QUEUED; } return new Download( download.request.copyWithMergedRequest(request), state, startTimeMs, nowMs, C.LENGTH_UNSET, stopReason, FAILURE_REASON_NONE); }
DownloadManager { static Download mergeRequest( Download download, DownloadRequest request, int stopReason, long nowMs) { @Download.State int state = download.state; long startTimeMs = state == STATE_REMOVING || download.isTerminalState() ? nowMs : download.startTimeMs; if (state == STATE_REMOVING || state == STATE_RESTARTING) { state = STATE_RESTARTING; } else if (stopReason != STOP_REASON_NONE) { state = STATE_STOPPED; } else { state = STATE_QUEUED; } return new Download( download.request.copyWithMergedRequest(request), state, startTimeMs, nowMs, C.LENGTH_UNSET, stopReason, FAILURE_REASON_NONE); } }
DownloadManager { static Download mergeRequest( Download download, DownloadRequest request, int stopReason, long nowMs) { @Download.State int state = download.state; long startTimeMs = state == STATE_REMOVING || download.isTerminalState() ? nowMs : download.startTimeMs; if (state == STATE_REMOVING || state == STATE_RESTARTING) { state = STATE_RESTARTING; } else if (stopReason != STOP_REASON_NONE) { state = STATE_STOPPED; } else { state = STATE_QUEUED; } return new Download( download.request.copyWithMergedRequest(request), state, startTimeMs, nowMs, C.LENGTH_UNSET, stopReason, FAILURE_REASON_NONE); } DownloadManager(
      Context context, DatabaseProvider databaseProvider, Cache cache, Factory upstreamFactory);  DownloadManager(
      Context context, WritableDownloadIndex downloadIndex, DownloaderFactory downloaderFactory); }
DownloadManager { static Download mergeRequest( Download download, DownloadRequest request, int stopReason, long nowMs) { @Download.State int state = download.state; long startTimeMs = state == STATE_REMOVING || download.isTerminalState() ? nowMs : download.startTimeMs; if (state == STATE_REMOVING || state == STATE_RESTARTING) { state = STATE_RESTARTING; } else if (stopReason != STOP_REASON_NONE) { state = STATE_STOPPED; } else { state = STATE_QUEUED; } return new Download( download.request.copyWithMergedRequest(request), state, startTimeMs, nowMs, C.LENGTH_UNSET, stopReason, FAILURE_REASON_NONE); } DownloadManager(
      Context context, DatabaseProvider databaseProvider, Cache cache, Factory upstreamFactory);  DownloadManager(
      Context context, WritableDownloadIndex downloadIndex, DownloaderFactory downloaderFactory); boolean isInitialized(); boolean isIdle(); boolean isWaitingForRequirements(); void addListener(Listener listener); void removeListener(Listener listener); Requirements getRequirements(); @Requirements.RequirementFlags int getNotMetRequirements(); void setRequirements(Requirements requirements); int getMaxParallelDownloads(); void setMaxParallelDownloads(int maxParallelDownloads); int getMinRetryCount(); void setMinRetryCount(int minRetryCount); DownloadIndex getDownloadIndex(); List<Download> getCurrentDownloads(); boolean getDownloadsPaused(); void resumeDownloads(); void pauseDownloads(); void setStopReason(@Nullable String id, int stopReason); void addDownload(DownloadRequest request); void addDownload(DownloadRequest request, int stopReason); void removeDownload(String id); void release(); }
DownloadManager { static Download mergeRequest( Download download, DownloadRequest request, int stopReason, long nowMs) { @Download.State int state = download.state; long startTimeMs = state == STATE_REMOVING || download.isTerminalState() ? nowMs : download.startTimeMs; if (state == STATE_REMOVING || state == STATE_RESTARTING) { state = STATE_RESTARTING; } else if (stopReason != STOP_REASON_NONE) { state = STATE_STOPPED; } else { state = STATE_QUEUED; } return new Download( download.request.copyWithMergedRequest(request), state, startTimeMs, nowMs, C.LENGTH_UNSET, stopReason, FAILURE_REASON_NONE); } DownloadManager(
      Context context, DatabaseProvider databaseProvider, Cache cache, Factory upstreamFactory);  DownloadManager(
      Context context, WritableDownloadIndex downloadIndex, DownloaderFactory downloaderFactory); boolean isInitialized(); boolean isIdle(); boolean isWaitingForRequirements(); void addListener(Listener listener); void removeListener(Listener listener); Requirements getRequirements(); @Requirements.RequirementFlags int getNotMetRequirements(); void setRequirements(Requirements requirements); int getMaxParallelDownloads(); void setMaxParallelDownloads(int maxParallelDownloads); int getMinRetryCount(); void setMinRetryCount(int minRetryCount); DownloadIndex getDownloadIndex(); List<Download> getCurrentDownloads(); boolean getDownloadsPaused(); void resumeDownloads(); void pauseDownloads(); void setStopReason(@Nullable String id, int stopReason); void addDownload(DownloadRequest request); void addDownload(DownloadRequest request, int stopReason); void removeDownload(String id); void release(); static final int DEFAULT_MAX_PARALLEL_DOWNLOADS; static final int DEFAULT_MIN_RETRY_COUNT; static final Requirements DEFAULT_REQUIREMENTS; }