Fix merging download action to completed and stop flag set download

PiperOrigin-RevId: 238002393
This commit is contained in:
eguven 2019-03-12 13:31:08 +00:00 committed by Oliver Woodman
parent 76e9950409
commit 9c6c74d564
2 changed files with 19 additions and 3 deletions

View File

@ -247,7 +247,7 @@ public final class DownloadState {
type,
action.uri,
action.customCacheKey,
getNextState(state, action.isRemoveAction),
getNextState(state, stopFlags != 0, action.isRemoveAction),
/* downloadPercentage= */ C.PERCENTAGE_UNSET,
downloadedBytes,
/* totalBytes= */ C.LENGTH_UNSET,
@ -261,14 +261,14 @@ public final class DownloadState {
action.data);
}
private static int getNextState(int currentState, boolean remove) {
private static int getNextState(int currentState, boolean stopFlagsSet, boolean remove) {
int nextState;
if (remove) {
nextState = STATE_REMOVING;
} else {
if (currentState == STATE_REMOVING || currentState == STATE_RESTARTING) {
nextState = STATE_RESTARTING;
} else if (currentState == STATE_STOPPED) {
} else if (stopFlagsSet) {
nextState = STATE_STOPPED;
} else {
nextState = STATE_QUEUED;

View File

@ -195,6 +195,22 @@ public class DownloadStateTest {
assertEqual(mergedDownloadState, expectedDownloadState);
}
@Test
public void mergeAction_stopFlagSetButNotInStoppedState_stateBecomesStopped() {
DownloadAction downloadAction = createDownloadAction();
DownloadStateBuilder downloadStateBuilder =
new DownloadStateBuilder(downloadAction)
.setState(DownloadState.STATE_COMPLETED)
.setStopFlags(DownloadState.STOP_FLAG_MANUAL);
DownloadState downloadState = downloadStateBuilder.build();
DownloadState mergedDownloadState = downloadState.mergeAction(downloadAction);
DownloadState expectedDownloadState =
downloadStateBuilder.setState(DownloadState.STATE_STOPPED).build();
assertEqual(mergedDownloadState, expectedDownloadState);
}
@Test
public void mergeAction_restartingDownloadRemoveAction_stateBecomesRemoving() {
DownloadAction downloadAction = createRemoveAction();