Commit 9c6c74d5 by eguven Committed by Oliver Woodman

Fix merging download action to completed and stop flag set download

PiperOrigin-RevId: 238002393
parent 76e99504
......@@ -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;
......
......@@ -196,6 +196,22 @@ public class DownloadStateTest {
}
@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();
DownloadStateBuilder downloadStateBuilder =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment