mirror of
https://github.com/androidx/media.git
synced 2025-05-16 20:19:57 +08:00
Fix merging download action to completed and stop flag set download
PiperOrigin-RevId: 238002393
This commit is contained in:
parent
76e9950409
commit
9c6c74d564
@ -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;
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user