Commit d088be7a by eguven Committed by Oliver Woodman

Remove DownloadState.stopFlags

PiperOrigin-RevId: 238442845
parent f566c948
...@@ -53,7 +53,6 @@ public final class DefaultDownloadIndex implements DownloadIndex { ...@@ -53,7 +53,6 @@ public final class DefaultDownloadIndex implements DownloadIndex {
private static final String COLUMN_DOWNLOADED_BYTES = "downloaded_bytes"; private static final String COLUMN_DOWNLOADED_BYTES = "downloaded_bytes";
private static final String COLUMN_TOTAL_BYTES = "total_bytes"; private static final String COLUMN_TOTAL_BYTES = "total_bytes";
private static final String COLUMN_FAILURE_REASON = "failure_reason"; private static final String COLUMN_FAILURE_REASON = "failure_reason";
private static final String COLUMN_STOP_FLAGS = "stop_flags";
private static final String COLUMN_NOT_MET_REQUIREMENTS = "not_met_requirements"; private static final String COLUMN_NOT_MET_REQUIREMENTS = "not_met_requirements";
private static final String COLUMN_MANUAL_STOP_REASON = "manual_stop_reason"; private static final String COLUMN_MANUAL_STOP_REASON = "manual_stop_reason";
private static final String COLUMN_START_TIME_MS = "start_time_ms"; private static final String COLUMN_START_TIME_MS = "start_time_ms";
...@@ -61,6 +60,10 @@ public final class DefaultDownloadIndex implements DownloadIndex { ...@@ -61,6 +60,10 @@ public final class DefaultDownloadIndex implements DownloadIndex {
private static final String COLUMN_STREAM_KEYS = "stream_keys"; private static final String COLUMN_STREAM_KEYS = "stream_keys";
private static final String COLUMN_CUSTOM_METADATA = "custom_metadata"; private static final String COLUMN_CUSTOM_METADATA = "custom_metadata";
@SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
private static final String COLUMN_STOP_FLAGS = "stop_flags";
private static final int COLUMN_INDEX_ID = 0; private static final int COLUMN_INDEX_ID = 0;
private static final int COLUMN_INDEX_TYPE = 1; private static final int COLUMN_INDEX_TYPE = 1;
private static final int COLUMN_INDEX_URI = 2; private static final int COLUMN_INDEX_URI = 2;
...@@ -70,13 +73,12 @@ public final class DefaultDownloadIndex implements DownloadIndex { ...@@ -70,13 +73,12 @@ public final class DefaultDownloadIndex implements DownloadIndex {
private static final int COLUMN_INDEX_DOWNLOADED_BYTES = 6; private static final int COLUMN_INDEX_DOWNLOADED_BYTES = 6;
private static final int COLUMN_INDEX_TOTAL_BYTES = 7; private static final int COLUMN_INDEX_TOTAL_BYTES = 7;
private static final int COLUMN_INDEX_FAILURE_REASON = 8; private static final int COLUMN_INDEX_FAILURE_REASON = 8;
private static final int COLUMN_INDEX_STOP_FLAGS = 9; private static final int COLUMN_INDEX_NOT_MET_REQUIREMENTS = 9;
private static final int COLUMN_INDEX_NOT_MET_REQUIREMENTS = 10; private static final int COLUMN_INDEX_MANUAL_STOP_REASON = 10;
private static final int COLUMN_INDEX_MANUAL_STOP_REASON = 11; private static final int COLUMN_INDEX_START_TIME_MS = 11;
private static final int COLUMN_INDEX_START_TIME_MS = 12; private static final int COLUMN_INDEX_UPDATE_TIME_MS = 12;
private static final int COLUMN_INDEX_UPDATE_TIME_MS = 13; private static final int COLUMN_INDEX_STREAM_KEYS = 13;
private static final int COLUMN_INDEX_STREAM_KEYS = 14; private static final int COLUMN_INDEX_CUSTOM_METADATA = 14;
private static final int COLUMN_INDEX_CUSTOM_METADATA = 15;
private static final String WHERE_ID_EQUALS = COLUMN_ID + " = ?"; private static final String WHERE_ID_EQUALS = COLUMN_ID + " = ?";
...@@ -91,7 +93,6 @@ public final class DefaultDownloadIndex implements DownloadIndex { ...@@ -91,7 +93,6 @@ public final class DefaultDownloadIndex implements DownloadIndex {
COLUMN_DOWNLOADED_BYTES, COLUMN_DOWNLOADED_BYTES,
COLUMN_TOTAL_BYTES, COLUMN_TOTAL_BYTES,
COLUMN_FAILURE_REASON, COLUMN_FAILURE_REASON,
COLUMN_STOP_FLAGS,
COLUMN_NOT_MET_REQUIREMENTS, COLUMN_NOT_MET_REQUIREMENTS,
COLUMN_MANUAL_STOP_REASON, COLUMN_MANUAL_STOP_REASON,
COLUMN_START_TIME_MS, COLUMN_START_TIME_MS,
...@@ -210,7 +211,7 @@ public final class DefaultDownloadIndex implements DownloadIndex { ...@@ -210,7 +211,7 @@ public final class DefaultDownloadIndex implements DownloadIndex {
values.put(COLUMN_DOWNLOADED_BYTES, downloadState.downloadedBytes); values.put(COLUMN_DOWNLOADED_BYTES, downloadState.downloadedBytes);
values.put(COLUMN_TOTAL_BYTES, downloadState.totalBytes); values.put(COLUMN_TOTAL_BYTES, downloadState.totalBytes);
values.put(COLUMN_FAILURE_REASON, downloadState.failureReason); values.put(COLUMN_FAILURE_REASON, downloadState.failureReason);
values.put(COLUMN_STOP_FLAGS, downloadState.stopFlags); values.put(COLUMN_STOP_FLAGS, /*stopFlags*/ 0);
values.put(COLUMN_NOT_MET_REQUIREMENTS, downloadState.notMetRequirements); values.put(COLUMN_NOT_MET_REQUIREMENTS, downloadState.notMetRequirements);
values.put(COLUMN_MANUAL_STOP_REASON, downloadState.manualStopReason); values.put(COLUMN_MANUAL_STOP_REASON, downloadState.manualStopReason);
values.put(COLUMN_START_TIME_MS, downloadState.startTimeMs); values.put(COLUMN_START_TIME_MS, downloadState.startTimeMs);
...@@ -288,7 +289,6 @@ public final class DefaultDownloadIndex implements DownloadIndex { ...@@ -288,7 +289,6 @@ public final class DefaultDownloadIndex implements DownloadIndex {
cursor.getLong(COLUMN_INDEX_DOWNLOADED_BYTES), cursor.getLong(COLUMN_INDEX_DOWNLOADED_BYTES),
cursor.getLong(COLUMN_INDEX_TOTAL_BYTES), cursor.getLong(COLUMN_INDEX_TOTAL_BYTES),
cursor.getInt(COLUMN_INDEX_FAILURE_REASON), cursor.getInt(COLUMN_INDEX_FAILURE_REASON),
cursor.getInt(COLUMN_INDEX_STOP_FLAGS),
cursor.getInt(COLUMN_INDEX_NOT_MET_REQUIREMENTS), cursor.getInt(COLUMN_INDEX_NOT_MET_REQUIREMENTS),
cursor.getInt(COLUMN_INDEX_MANUAL_STOP_REASON), cursor.getInt(COLUMN_INDEX_MANUAL_STOP_REASON),
cursor.getLong(COLUMN_INDEX_START_TIME_MS), cursor.getLong(COLUMN_INDEX_START_TIME_MS),
......
...@@ -76,20 +76,10 @@ public final class DownloadState { ...@@ -76,20 +76,10 @@ public final class DownloadState {
/** The download is failed because of unknown reason. */ /** The download is failed because of unknown reason. */
public static final int FAILURE_REASON_UNKNOWN = 1; public static final int FAILURE_REASON_UNKNOWN = 1;
/** /** The download isn't manually stopped. */
* Download stop flags. Possible flag values are {@link #STOP_FLAG_MANUAL} and {@link public static final int MANUAL_STOP_REASON_NONE = 0;
* #STOP_FLAG_REQUIREMENTS_NOT_MET}. /** The download is manually stopped but a reason isn't specified. */
*/ public static final int MANUAL_STOP_REASON_UNDEFINED = Integer.MAX_VALUE;
@Documented
@Retention(RetentionPolicy.SOURCE)
@IntDef(
flag = true,
value = {STOP_FLAG_MANUAL, STOP_FLAG_REQUIREMENTS_NOT_MET})
public @interface StopFlags {}
/** Download is stopped by the application. */
public static final int STOP_FLAG_MANUAL = 1;
/** Download is stopped as the requirements are not met. */
public static final int STOP_FLAG_REQUIREMENTS_NOT_MET = 1 << 1;
/** Returns the state string for the given state value. */ /** Returns the state string for the given state value. */
public static String getStateString(@State int state) { public static String getStateString(@State int state) {
...@@ -156,11 +146,9 @@ public final class DownloadState { ...@@ -156,11 +146,9 @@ public final class DownloadState {
* #FAILURE_REASON_NONE}. * #FAILURE_REASON_NONE}.
*/ */
@FailureReason public final int failureReason; @FailureReason public final int failureReason;
/** Download stop flags. These flags stop downloading any content. */
@StopFlags public final int stopFlags;
/** Not met requirements to download. */ /** Not met requirements to download. */
@Requirements.RequirementFlags public final int notMetRequirements; @Requirements.RequirementFlags public final int notMetRequirements;
/** If {@link #STOP_FLAG_MANUAL} is set then this field holds the manual stop reason. */ /** The manual stop reason. */
public final int manualStopReason; public final int manualStopReason;
/** /**
...@@ -183,7 +171,6 @@ public final class DownloadState { ...@@ -183,7 +171,6 @@ public final class DownloadState {
/* downloadedBytes= */ 0, /* downloadedBytes= */ 0,
/* totalBytes= */ C.LENGTH_UNSET, /* totalBytes= */ C.LENGTH_UNSET,
FAILURE_REASON_NONE, FAILURE_REASON_NONE,
/* stopFlags= */ 0,
/* notMetRequirements= */ 0, /* notMetRequirements= */ 0,
/* manualStopReason= */ 0, /* manualStopReason= */ 0,
/* startTimeMs= */ currentTimeMs, /* startTimeMs= */ currentTimeMs,
...@@ -202,7 +189,6 @@ public final class DownloadState { ...@@ -202,7 +189,6 @@ public final class DownloadState {
long downloadedBytes, long downloadedBytes,
long totalBytes, long totalBytes,
@FailureReason int failureReason, @FailureReason int failureReason,
@StopFlags int stopFlags,
@RequirementFlags int notMetRequirements, @RequirementFlags int notMetRequirements,
int manualStopReason, int manualStopReason,
long startTimeMs, long startTimeMs,
...@@ -210,10 +196,9 @@ public final class DownloadState { ...@@ -210,10 +196,9 @@ public final class DownloadState {
StreamKey[] streamKeys, StreamKey[] streamKeys,
byte[] customMetadata) { byte[] customMetadata) {
Assertions.checkState((failureReason == FAILURE_REASON_NONE) == (state != STATE_FAILED)); Assertions.checkState((failureReason == FAILURE_REASON_NONE) == (state != STATE_FAILED));
Assertions.checkState(stopFlags == 0 || (state != STATE_DOWNLOADING && state != STATE_QUEUED)); if (manualStopReason != 0 || notMetRequirements != 0) {
Assertions.checkState( Assertions.checkState(state != STATE_DOWNLOADING && state != STATE_QUEUED);
((stopFlags & STOP_FLAG_REQUIREMENTS_NOT_MET) == 0) == (notMetRequirements == 0)); }
Assertions.checkState(((stopFlags & STOP_FLAG_MANUAL) != 0) || (manualStopReason == 0));
this.id = id; this.id = id;
this.type = type; this.type = type;
this.uri = uri; this.uri = uri;
...@@ -223,7 +208,6 @@ public final class DownloadState { ...@@ -223,7 +208,6 @@ public final class DownloadState {
this.downloadedBytes = downloadedBytes; this.downloadedBytes = downloadedBytes;
this.totalBytes = totalBytes; this.totalBytes = totalBytes;
this.failureReason = failureReason; this.failureReason = failureReason;
this.stopFlags = stopFlags;
this.notMetRequirements = notMetRequirements; this.notMetRequirements = notMetRequirements;
this.manualStopReason = manualStopReason; this.manualStopReason = manualStopReason;
this.startTimeMs = startTimeMs; this.startTimeMs = startTimeMs;
...@@ -247,12 +231,12 @@ public final class DownloadState { ...@@ -247,12 +231,12 @@ public final class DownloadState {
type, type,
action.uri, action.uri,
action.customCacheKey, action.customCacheKey,
getNextState(state, stopFlags != 0, action.isRemoveAction), getNextState(
state, manualStopReason != 0 || notMetRequirements != 0, action.isRemoveAction),
/* downloadPercentage= */ C.PERCENTAGE_UNSET, /* downloadPercentage= */ C.PERCENTAGE_UNSET,
downloadedBytes, downloadedBytes,
/* totalBytes= */ C.LENGTH_UNSET, /* totalBytes= */ C.LENGTH_UNSET,
FAILURE_REASON_NONE, FAILURE_REASON_NONE,
stopFlags,
notMetRequirements, notMetRequirements,
manualStopReason, manualStopReason,
startTimeMs, startTimeMs,
...@@ -261,14 +245,14 @@ public final class DownloadState { ...@@ -261,14 +245,14 @@ public final class DownloadState {
action.data); action.data);
} }
private static int getNextState(int currentState, boolean stopFlagsSet, boolean remove) { private static int getNextState(int currentState, boolean isStopped, 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 (stopFlagsSet) { } else if (isStopped) {
nextState = STATE_STOPPED; nextState = STATE_STOPPED;
} else { } else {
nextState = STATE_QUEUED; nextState = STATE_QUEUED;
......
...@@ -81,8 +81,6 @@ public class DefaultDownloadIndexTest { ...@@ -81,8 +81,6 @@ public class DefaultDownloadIndexTest {
.setDownloadedBytes(200) .setDownloadedBytes(200)
.setTotalBytes(400) .setTotalBytes(400)
.setFailureReason(DownloadState.FAILURE_REASON_UNKNOWN) .setFailureReason(DownloadState.FAILURE_REASON_UNKNOWN)
.setStopFlags(
DownloadState.STOP_FLAG_REQUIREMENTS_NOT_MET | DownloadState.STOP_FLAG_MANUAL)
.setNotMetRequirements(0x87654321) .setNotMetRequirements(0x87654321)
.setManualStopReason(0x12345678) .setManualStopReason(0x12345678)
.setStartTimeMs(10) .setStartTimeMs(10)
......
...@@ -36,7 +36,6 @@ class DownloadStateBuilder { ...@@ -36,7 +36,6 @@ class DownloadStateBuilder {
private long downloadedBytes; private long downloadedBytes;
private long totalBytes; private long totalBytes;
private int failureReason; private int failureReason;
private int stopFlags;
private int notMetRequirements; private int notMetRequirements;
private int manualStopReason; private int manualStopReason;
private long startTimeMs; private long startTimeMs;
...@@ -74,7 +73,6 @@ class DownloadStateBuilder { ...@@ -74,7 +73,6 @@ class DownloadStateBuilder {
this.downloadedBytes = (long) 0; this.downloadedBytes = (long) 0;
this.totalBytes = (long) C.LENGTH_UNSET; this.totalBytes = (long) C.LENGTH_UNSET;
this.failureReason = DownloadState.FAILURE_REASON_NONE; this.failureReason = DownloadState.FAILURE_REASON_NONE;
this.stopFlags = 0;
this.startTimeMs = (long) 0; this.startTimeMs = (long) 0;
this.updateTimeMs = (long) 0; this.updateTimeMs = (long) 0;
this.streamKeys = streamKeys; this.streamKeys = streamKeys;
...@@ -131,11 +129,6 @@ class DownloadStateBuilder { ...@@ -131,11 +129,6 @@ class DownloadStateBuilder {
return this; return this;
} }
public DownloadStateBuilder setStopFlags(int stopFlags) {
this.stopFlags = stopFlags;
return this;
}
public DownloadStateBuilder setNotMetRequirements(int notMetRequirements) { public DownloadStateBuilder setNotMetRequirements(int notMetRequirements) {
this.notMetRequirements = notMetRequirements; this.notMetRequirements = notMetRequirements;
return this; return this;
...@@ -177,7 +170,6 @@ class DownloadStateBuilder { ...@@ -177,7 +170,6 @@ class DownloadStateBuilder {
downloadedBytes, downloadedBytes,
totalBytes, totalBytes,
failureReason, failureReason,
stopFlags,
notMetRequirements, notMetRequirements,
manualStopReason, manualStopReason,
startTimeMs, startTimeMs,
......
...@@ -171,7 +171,7 @@ public class DownloadStateTest { ...@@ -171,7 +171,7 @@ public class DownloadStateTest {
DownloadStateBuilder downloadStateBuilder = DownloadStateBuilder downloadStateBuilder =
new DownloadStateBuilder(downloadAction) new DownloadStateBuilder(downloadAction)
.setState(DownloadState.STATE_STOPPED) .setState(DownloadState.STATE_STOPPED)
.setStopFlags(DownloadState.STOP_FLAG_MANUAL); .setManualStopReason(DownloadState.MANUAL_STOP_REASON_UNDEFINED);
DownloadState downloadState = downloadStateBuilder.build(); DownloadState downloadState = downloadStateBuilder.build();
DownloadState mergedDownloadState = downloadState.mergeAction(downloadAction); DownloadState mergedDownloadState = downloadState.mergeAction(downloadAction);
...@@ -185,7 +185,7 @@ public class DownloadStateTest { ...@@ -185,7 +185,7 @@ public class DownloadStateTest {
DownloadStateBuilder downloadStateBuilder = DownloadStateBuilder downloadStateBuilder =
new DownloadStateBuilder(downloadAction) new DownloadStateBuilder(downloadAction)
.setState(DownloadState.STATE_STOPPED) .setState(DownloadState.STATE_STOPPED)
.setStopFlags(DownloadState.STOP_FLAG_MANUAL); .setManualStopReason(DownloadState.MANUAL_STOP_REASON_UNDEFINED);
DownloadState downloadState = downloadStateBuilder.build(); DownloadState downloadState = downloadStateBuilder.build();
DownloadState mergedDownloadState = downloadState.mergeAction(downloadAction); DownloadState mergedDownloadState = downloadState.mergeAction(downloadAction);
...@@ -196,12 +196,28 @@ public class DownloadStateTest { ...@@ -196,12 +196,28 @@ public class DownloadStateTest {
} }
@Test @Test
public void mergeAction_stopFlagSetButNotInStoppedState_stateBecomesStopped() { public void mergeAction_manualStopReasonSetButNotInStoppedState_stateBecomesStopped() {
DownloadAction downloadAction = createDownloadAction(); DownloadAction downloadAction = createDownloadAction();
DownloadStateBuilder downloadStateBuilder = DownloadStateBuilder downloadStateBuilder =
new DownloadStateBuilder(downloadAction) new DownloadStateBuilder(downloadAction)
.setState(DownloadState.STATE_COMPLETED) .setState(DownloadState.STATE_COMPLETED)
.setStopFlags(DownloadState.STOP_FLAG_MANUAL); .setManualStopReason(DownloadState.MANUAL_STOP_REASON_UNDEFINED);
DownloadState downloadState = downloadStateBuilder.build();
DownloadState mergedDownloadState = downloadState.mergeAction(downloadAction);
DownloadState expectedDownloadState =
downloadStateBuilder.setState(DownloadState.STATE_STOPPED).build();
assertEqual(mergedDownloadState, expectedDownloadState);
}
@Test
public void mergeAction_notMetRequirementsSetButNotInStoppedState_stateBecomesStopped() {
DownloadAction downloadAction = createDownloadAction();
DownloadStateBuilder downloadStateBuilder =
new DownloadStateBuilder(downloadAction)
.setState(DownloadState.STATE_COMPLETED)
.setNotMetRequirements(0x12345678);
DownloadState downloadState = downloadStateBuilder.build(); DownloadState downloadState = downloadStateBuilder.build();
DownloadState mergedDownloadState = downloadState.mergeAction(downloadAction); DownloadState mergedDownloadState = downloadState.mergeAction(downloadAction);
...@@ -325,7 +341,7 @@ public class DownloadStateTest { ...@@ -325,7 +341,7 @@ public class DownloadStateTest {
if (downloadState.failureReason != that.failureReason) { if (downloadState.failureReason != that.failureReason) {
return false; return false;
} }
if (downloadState.stopFlags != that.stopFlags) { if (downloadState.manualStopReason != that.manualStopReason) {
return false; return false;
} }
if (downloadState.notMetRequirements != that.notMetRequirements) { if (downloadState.notMetRequirements != that.notMetRequirements) {
......
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