mirror of
https://github.com/androidx/media.git
synced 2025-05-17 12:39:52 +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,
|
type,
|
||||||
action.uri,
|
action.uri,
|
||||||
action.customCacheKey,
|
action.customCacheKey,
|
||||||
getNextState(state, action.isRemoveAction),
|
getNextState(state, stopFlags != 0, action.isRemoveAction),
|
||||||
/* downloadPercentage= */ C.PERCENTAGE_UNSET,
|
/* downloadPercentage= */ C.PERCENTAGE_UNSET,
|
||||||
downloadedBytes,
|
downloadedBytes,
|
||||||
/* totalBytes= */ C.LENGTH_UNSET,
|
/* totalBytes= */ C.LENGTH_UNSET,
|
||||||
@ -261,14 +261,14 @@ public final class DownloadState {
|
|||||||
action.data);
|
action.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getNextState(int currentState, boolean remove) {
|
private static int getNextState(int currentState, boolean stopFlagsSet, boolean remove) {
|
||||||
int nextState;
|
int nextState;
|
||||||
if (remove) {
|
if (remove) {
|
||||||
nextState = STATE_REMOVING;
|
nextState = STATE_REMOVING;
|
||||||
} else {
|
} else {
|
||||||
if (currentState == STATE_REMOVING || currentState == STATE_RESTARTING) {
|
if (currentState == STATE_REMOVING || currentState == STATE_RESTARTING) {
|
||||||
nextState = STATE_RESTARTING;
|
nextState = STATE_RESTARTING;
|
||||||
} else if (currentState == STATE_STOPPED) {
|
} else if (stopFlagsSet) {
|
||||||
nextState = STATE_STOPPED;
|
nextState = STATE_STOPPED;
|
||||||
} else {
|
} else {
|
||||||
nextState = STATE_QUEUED;
|
nextState = STATE_QUEUED;
|
||||||
|
@ -195,6 +195,22 @@ public class DownloadStateTest {
|
|||||||
assertEqual(mergedDownloadState, expectedDownloadState);
|
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
|
@Test
|
||||||
public void mergeAction_restartingDownloadRemoveAction_stateBecomesRemoving() {
|
public void mergeAction_restartingDownloadRemoveAction_stateBecomesRemoving() {
|
||||||
DownloadAction downloadAction = createRemoveAction();
|
DownloadAction downloadAction = createRemoveAction();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user