@Test public void mergeRequest_addNewDownloadAsCompleted() throws IOException { StreamKey streamKey1 = new StreamKey( 3, 4, 5); StreamKey streamKey2 = new StreamKey( 0, 1, 2); DownloadRequest request1 = new DownloadRequest( "id1", TYPE_PROGRESSIVE, Uri.parse("https: asList(streamKey1), "key123", new byte[] {1, 2, 3, 4}); DownloadRequest request2 = new DownloadRequest( "id2", TYPE_PROGRESSIVE, Uri.parse("https: asList(streamKey2), "key123", new byte[] {5, 4, 3, 2, 1}); ActionFileUpgradeUtil.mergeRequest( request1, downloadIndex, false, NOW_MS); ActionFileUpgradeUtil.mergeRequest( request1, downloadIndex, true, NOW_MS); assertThat(downloadIndex.getDownload(request1.id).state).isEqualTo(Download.STATE_QUEUED); ActionFileUpgradeUtil.mergeRequest( request2, downloadIndex, true, NOW_MS); assertThat(downloadIndex.getDownload(request2.id).state).isEqualTo(Download.STATE_COMPLETED); }
static void mergeRequest( DownloadRequest request, DefaultDownloadIndex downloadIndex, boolean addNewDownloadAsCompleted, long nowMs) throws IOException { Download download = downloadIndex.getDownload(request.id); if (download != null) { download = DownloadManager.mergeRequest(download, request, download.stopReason, nowMs); } else { download = new Download( request, addNewDownloadAsCompleted ? Download.STATE_COMPLETED : STATE_QUEUED, nowMs, nowMs, C.LENGTH_UNSET, Download.STOP_REASON_NONE, Download.FAILURE_REASON_NONE); } downloadIndex.putDownload(download); }
ActionFileUpgradeUtil { static void mergeRequest( DownloadRequest request, DefaultDownloadIndex downloadIndex, boolean addNewDownloadAsCompleted, long nowMs) throws IOException { Download download = downloadIndex.getDownload(request.id); if (download != null) { download = DownloadManager.mergeRequest(download, request, download.stopReason, nowMs); } else { download = new Download( request, addNewDownloadAsCompleted ? Download.STATE_COMPLETED : STATE_QUEUED, nowMs, nowMs, C.LENGTH_UNSET, Download.STOP_REASON_NONE, Download.FAILURE_REASON_NONE); } downloadIndex.putDownload(download); } }
ActionFileUpgradeUtil { static void mergeRequest( DownloadRequest request, DefaultDownloadIndex downloadIndex, boolean addNewDownloadAsCompleted, long nowMs) throws IOException { Download download = downloadIndex.getDownload(request.id); if (download != null) { download = DownloadManager.mergeRequest(download, request, download.stopReason, nowMs); } else { download = new Download( request, addNewDownloadAsCompleted ? Download.STATE_COMPLETED : STATE_QUEUED, nowMs, nowMs, C.LENGTH_UNSET, Download.STOP_REASON_NONE, Download.FAILURE_REASON_NONE); } downloadIndex.putDownload(download); } private  ActionFileUpgradeUtil(); }
ActionFileUpgradeUtil { static void mergeRequest( DownloadRequest request, DefaultDownloadIndex downloadIndex, boolean addNewDownloadAsCompleted, long nowMs) throws IOException { Download download = downloadIndex.getDownload(request.id); if (download != null) { download = DownloadManager.mergeRequest(download, request, download.stopReason, nowMs); } else { download = new Download( request, addNewDownloadAsCompleted ? Download.STATE_COMPLETED : STATE_QUEUED, nowMs, nowMs, C.LENGTH_UNSET, Download.STOP_REASON_NONE, Download.FAILURE_REASON_NONE); } downloadIndex.putDownload(download); } private  ActionFileUpgradeUtil(); @SuppressWarnings("deprecation") static void upgradeAndDelete(
      File actionFilePath,
      @Nullable DownloadIdProvider downloadIdProvider,
      DefaultDownloadIndex downloadIndex,
      boolean deleteOnFailure,
      boolean addNewDownloadsAsCompleted); }
ActionFileUpgradeUtil { static void mergeRequest( DownloadRequest request, DefaultDownloadIndex downloadIndex, boolean addNewDownloadAsCompleted, long nowMs) throws IOException { Download download = downloadIndex.getDownload(request.id); if (download != null) { download = DownloadManager.mergeRequest(download, request, download.stopReason, nowMs); } else { download = new Download( request, addNewDownloadAsCompleted ? Download.STATE_COMPLETED : STATE_QUEUED, nowMs, nowMs, C.LENGTH_UNSET, Download.STOP_REASON_NONE, Download.FAILURE_REASON_NONE); } downloadIndex.putDownload(download); } private  ActionFileUpgradeUtil(); @SuppressWarnings("deprecation") static void upgradeAndDelete(
      File actionFilePath,
      @Nullable DownloadIdProvider downloadIdProvider,
      DefaultDownloadIndex downloadIndex,
      boolean deleteOnFailure,
      boolean addNewDownloadsAsCompleted);  }