mirror of
https://github.com/androidx/media.git
synced 2025-05-16 20:19:57 +08:00
Rename manualStopReason to stopReason
PiperOrigin-RevId: 244210737
This commit is contained in:
parent
6d8bd34590
commit
138da6d519
@ -90,7 +90,7 @@ public final class ActionFileUpgradeUtil {
|
||||
DownloadRequest request, DefaultDownloadIndex downloadIndex) throws IOException {
|
||||
Download download = downloadIndex.getDownload(request.id);
|
||||
if (download != null) {
|
||||
download = DownloadManager.mergeRequest(download, request, download.manualStopReason);
|
||||
download = DownloadManager.mergeRequest(download, request, download.stopReason);
|
||||
} else {
|
||||
long nowMs = System.currentTimeMillis();
|
||||
download =
|
||||
@ -98,7 +98,7 @@ public final class ActionFileUpgradeUtil {
|
||||
request,
|
||||
STATE_QUEUED,
|
||||
Download.FAILURE_REASON_NONE,
|
||||
Download.MANUAL_STOP_REASON_NONE,
|
||||
Download.STOP_REASON_NONE,
|
||||
/* startTimeMs= */ nowMs,
|
||||
/* updateTimeMs= */ nowMs);
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
|
||||
private static final String COLUMN_DOWNLOADED_BYTES = "downloaded_bytes";
|
||||
private static final String COLUMN_TOTAL_BYTES = "total_bytes";
|
||||
private static final String COLUMN_FAILURE_REASON = "failure_reason";
|
||||
private static final String COLUMN_MANUAL_STOP_REASON = "manual_stop_reason";
|
||||
private static final String COLUMN_STOP_REASON = "manual_stop_reason";
|
||||
private static final String COLUMN_START_TIME_MS = "start_time_ms";
|
||||
private static final String COLUMN_UPDATE_TIME_MS = "update_time_ms";
|
||||
|
||||
@ -82,7 +82,7 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
|
||||
private static final int COLUMN_INDEX_DOWNLOADED_BYTES = 8;
|
||||
private static final int COLUMN_INDEX_TOTAL_BYTES = 9;
|
||||
private static final int COLUMN_INDEX_FAILURE_REASON = 10;
|
||||
private static final int COLUMN_INDEX_MANUAL_STOP_REASON = 11;
|
||||
private static final int COLUMN_INDEX_STOP_REASON = 11;
|
||||
private static final int COLUMN_INDEX_START_TIME_MS = 12;
|
||||
private static final int COLUMN_INDEX_UPDATE_TIME_MS = 13;
|
||||
|
||||
@ -103,7 +103,7 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
|
||||
COLUMN_DOWNLOADED_BYTES,
|
||||
COLUMN_TOTAL_BYTES,
|
||||
COLUMN_FAILURE_REASON,
|
||||
COLUMN_MANUAL_STOP_REASON,
|
||||
COLUMN_STOP_REASON,
|
||||
COLUMN_START_TIME_MS,
|
||||
COLUMN_UPDATE_TIME_MS
|
||||
};
|
||||
@ -135,7 +135,7 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
|
||||
+ " INTEGER NOT NULL,"
|
||||
+ COLUMN_NOT_MET_REQUIREMENTS
|
||||
+ " INTEGER NOT NULL,"
|
||||
+ COLUMN_MANUAL_STOP_REASON
|
||||
+ COLUMN_STOP_REASON
|
||||
+ " INTEGER NOT NULL,"
|
||||
+ COLUMN_START_TIME_MS
|
||||
+ " INTEGER NOT NULL,"
|
||||
@ -202,7 +202,7 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
|
||||
values.put(COLUMN_FAILURE_REASON, download.failureReason);
|
||||
values.put(COLUMN_STOP_FLAGS, 0);
|
||||
values.put(COLUMN_NOT_MET_REQUIREMENTS, 0);
|
||||
values.put(COLUMN_MANUAL_STOP_REASON, download.manualStopReason);
|
||||
values.put(COLUMN_STOP_REASON, download.stopReason);
|
||||
values.put(COLUMN_START_TIME_MS, download.startTimeMs);
|
||||
values.put(COLUMN_UPDATE_TIME_MS, download.updateTimeMs);
|
||||
try {
|
||||
@ -224,11 +224,11 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setManualStopReason(int manualStopReason) throws DatabaseIOException {
|
||||
public void setStopReason(int stopReason) throws DatabaseIOException {
|
||||
ensureInitialized();
|
||||
try {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(COLUMN_MANUAL_STOP_REASON, manualStopReason);
|
||||
values.put(COLUMN_STOP_REASON, stopReason);
|
||||
SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
|
||||
writableDatabase.update(TABLE_NAME, values, WHERE_STATE_TERMINAL, /* whereArgs= */ null);
|
||||
} catch (SQLException e) {
|
||||
@ -237,11 +237,11 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setManualStopReason(String id, int manualStopReason) throws DatabaseIOException {
|
||||
public void setStopReason(String id, int stopReason) throws DatabaseIOException {
|
||||
ensureInitialized();
|
||||
try {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(COLUMN_MANUAL_STOP_REASON, manualStopReason);
|
||||
values.put(COLUMN_STOP_REASON, stopReason);
|
||||
SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
|
||||
writableDatabase.update(
|
||||
TABLE_NAME, values, WHERE_STATE_TERMINAL + " AND " + WHERE_ID_EQUALS, new String[] {id});
|
||||
@ -332,7 +332,7 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
|
||||
request,
|
||||
cursor.getInt(COLUMN_INDEX_STATE),
|
||||
cursor.getInt(COLUMN_INDEX_FAILURE_REASON),
|
||||
cursor.getInt(COLUMN_INDEX_MANUAL_STOP_REASON),
|
||||
cursor.getInt(COLUMN_INDEX_STOP_REASON),
|
||||
cursor.getLong(COLUMN_INDEX_START_TIME_MS),
|
||||
cursor.getLong(COLUMN_INDEX_UPDATE_TIME_MS),
|
||||
cachingCounters);
|
||||
|
@ -46,7 +46,7 @@ public final class Download {
|
||||
// Important: These constants are persisted into DownloadIndex. Do not change them.
|
||||
/** The download is waiting to be started. */
|
||||
public static final int STATE_QUEUED = 0;
|
||||
/** The download is stopped for a specified {@link #manualStopReason}. */
|
||||
/** The download is stopped for a specified {@link #stopReason}. */
|
||||
public static final int STATE_STOPPED = 1;
|
||||
/** The download is currently started. */
|
||||
public static final int STATE_DOWNLOADING = 2;
|
||||
@ -69,8 +69,8 @@ public final class Download {
|
||||
/** The download is failed because of unknown reason. */
|
||||
public static final int FAILURE_REASON_UNKNOWN = 1;
|
||||
|
||||
/** The download isn't manually stopped. */
|
||||
public static final int MANUAL_STOP_REASON_NONE = 0;
|
||||
/** The download isn't stopped. */
|
||||
public static final int STOP_REASON_NONE = 0;
|
||||
|
||||
/** Returns the state string for the given state value. */
|
||||
public static String getStateString(@State int state) {
|
||||
@ -108,8 +108,8 @@ public final class Download {
|
||||
* #FAILURE_REASON_NONE}.
|
||||
*/
|
||||
@FailureReason public final int failureReason;
|
||||
/** The reason the download is manually stopped, or {@link #MANUAL_STOP_REASON_NONE}. */
|
||||
public final int manualStopReason;
|
||||
/** The reason the download is stopped, or {@link #STOP_REASON_NONE}. */
|
||||
public final int stopReason;
|
||||
|
||||
/* package */ CachingCounters counters;
|
||||
|
||||
@ -117,14 +117,14 @@ public final class Download {
|
||||
DownloadRequest request,
|
||||
@State int state,
|
||||
@FailureReason int failureReason,
|
||||
int manualStopReason,
|
||||
int stopReason,
|
||||
long startTimeMs,
|
||||
long updateTimeMs) {
|
||||
this(
|
||||
request,
|
||||
state,
|
||||
failureReason,
|
||||
manualStopReason,
|
||||
stopReason,
|
||||
startTimeMs,
|
||||
updateTimeMs,
|
||||
new CachingCounters());
|
||||
@ -134,19 +134,19 @@ public final class Download {
|
||||
DownloadRequest request,
|
||||
@State int state,
|
||||
@FailureReason int failureReason,
|
||||
int manualStopReason,
|
||||
int stopReason,
|
||||
long startTimeMs,
|
||||
long updateTimeMs,
|
||||
CachingCounters counters) {
|
||||
Assertions.checkNotNull(counters);
|
||||
Assertions.checkState((failureReason == FAILURE_REASON_NONE) == (state != STATE_FAILED));
|
||||
if (manualStopReason != 0) {
|
||||
if (stopReason != 0) {
|
||||
Assertions.checkState(state != STATE_DOWNLOADING && state != STATE_QUEUED);
|
||||
}
|
||||
this.request = request;
|
||||
this.state = state;
|
||||
this.failureReason = failureReason;
|
||||
this.manualStopReason = manualStopReason;
|
||||
this.stopReason = stopReason;
|
||||
this.startTimeMs = startTimeMs;
|
||||
this.updateTimeMs = updateTimeMs;
|
||||
this.counters = counters;
|
||||
|
@ -17,7 +17,6 @@ package com.google.android.exoplayer2.offline;
|
||||
|
||||
import static com.google.android.exoplayer2.offline.Download.FAILURE_REASON_NONE;
|
||||
import static com.google.android.exoplayer2.offline.Download.FAILURE_REASON_UNKNOWN;
|
||||
import static com.google.android.exoplayer2.offline.Download.MANUAL_STOP_REASON_NONE;
|
||||
import static com.google.android.exoplayer2.offline.Download.STATE_COMPLETED;
|
||||
import static com.google.android.exoplayer2.offline.Download.STATE_DOWNLOADING;
|
||||
import static com.google.android.exoplayer2.offline.Download.STATE_FAILED;
|
||||
@ -25,6 +24,7 @@ import static com.google.android.exoplayer2.offline.Download.STATE_QUEUED;
|
||||
import static com.google.android.exoplayer2.offline.Download.STATE_REMOVING;
|
||||
import static com.google.android.exoplayer2.offline.Download.STATE_RESTARTING;
|
||||
import static com.google.android.exoplayer2.offline.Download.STATE_STOPPED;
|
||||
import static com.google.android.exoplayer2.offline.Download.STOP_REASON_NONE;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
@ -128,7 +128,7 @@ public final class DownloadManager {
|
||||
private static final int MSG_INITIALIZE = 0;
|
||||
private static final int MSG_SET_DOWNLOADS_STARTED = 1;
|
||||
private static final int MSG_SET_NOT_MET_REQUIREMENTS = 2;
|
||||
private static final int MSG_SET_MANUAL_STOP_REASON = 3;
|
||||
private static final int MSG_SET_STOP_REASON = 3;
|
||||
private static final int MSG_ADD_DOWNLOAD = 4;
|
||||
private static final int MSG_REMOVE_DOWNLOAD = 5;
|
||||
private static final int MSG_DOWNLOAD_THREAD_STOPPED = 6;
|
||||
@ -346,10 +346,7 @@ public final class DownloadManager {
|
||||
return Collections.unmodifiableList(new ArrayList<>(downloads));
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts all downloads except those that are manually stopped (i.e. have a non-zero {@link
|
||||
* Download#manualStopReason}).
|
||||
*/
|
||||
/** Starts all downloads except those that have a non-zero {@link Download#stopReason}. */
|
||||
public void startDownloads() {
|
||||
pendingMessages++;
|
||||
internalHandler
|
||||
@ -366,17 +363,17 @@ public final class DownloadManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the manual stop reason for one or all downloads. To clear the manual stop reason, pass
|
||||
* {@link Download#MANUAL_STOP_REASON_NONE}.
|
||||
* Sets the stop reason for one or all downloads. To clear the stop reason, pass {@link
|
||||
* Download#STOP_REASON_NONE}.
|
||||
*
|
||||
* @param id The content id of the download to update, or {@code null} to set the manual stop
|
||||
* reason for all downloads.
|
||||
* @param manualStopReason The manual stop reason, or {@link Download#MANUAL_STOP_REASON_NONE}.
|
||||
* @param id The content id of the download to update, or {@code null} to set the stop reason for
|
||||
* all downloads.
|
||||
* @param stopReason The stop reason, or {@link Download#STOP_REASON_NONE}.
|
||||
*/
|
||||
public void setManualStopReason(@Nullable String id, int manualStopReason) {
|
||||
public void setStopReason(@Nullable String id, int stopReason) {
|
||||
pendingMessages++;
|
||||
internalHandler
|
||||
.obtainMessage(MSG_SET_MANUAL_STOP_REASON, manualStopReason, /* unused */ 0, id)
|
||||
.obtainMessage(MSG_SET_STOP_REASON, stopReason, /* unused */ 0, id)
|
||||
.sendToTarget();
|
||||
}
|
||||
|
||||
@ -386,20 +383,20 @@ public final class DownloadManager {
|
||||
* @param request The download request.
|
||||
*/
|
||||
public void addDownload(DownloadRequest request) {
|
||||
addDownload(request, Download.MANUAL_STOP_REASON_NONE);
|
||||
addDownload(request, Download.STOP_REASON_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a download defined by the given request and with the specified manual stop reason.
|
||||
* Adds a download defined by the given request and with the specified stop reason.
|
||||
*
|
||||
* @param request The download request.
|
||||
* @param manualStopReason An initial manual stop reason for the download, or {@link
|
||||
* Download#MANUAL_STOP_REASON_NONE} if the download should be started.
|
||||
* @param stopReason An initial stop reason for the download, or {@link Download#STOP_REASON_NONE}
|
||||
* if the download should be started.
|
||||
*/
|
||||
public void addDownload(DownloadRequest request, int manualStopReason) {
|
||||
public void addDownload(DownloadRequest request, int stopReason) {
|
||||
pendingMessages++;
|
||||
internalHandler
|
||||
.obtainMessage(MSG_ADD_DOWNLOAD, manualStopReason, /* unused */ 0, request)
|
||||
.obtainMessage(MSG_ADD_DOWNLOAD, stopReason, /* unused */ 0, request)
|
||||
.sendToTarget();
|
||||
}
|
||||
|
||||
@ -552,15 +549,15 @@ public final class DownloadManager {
|
||||
notMetRequirements = message.arg1;
|
||||
setNotMetRequirementsInternal(notMetRequirements);
|
||||
break;
|
||||
case MSG_SET_MANUAL_STOP_REASON:
|
||||
case MSG_SET_STOP_REASON:
|
||||
String id = (String) message.obj;
|
||||
int manualStopReason = message.arg1;
|
||||
setManualStopReasonInternal(id, manualStopReason);
|
||||
int stopReason = message.arg1;
|
||||
setStopReasonInternal(id, stopReason);
|
||||
break;
|
||||
case MSG_ADD_DOWNLOAD:
|
||||
DownloadRequest request = (DownloadRequest) message.obj;
|
||||
manualStopReason = message.arg1;
|
||||
addDownloadInternal(request, manualStopReason);
|
||||
stopReason = message.arg1;
|
||||
addDownloadInternal(request, stopReason);
|
||||
break;
|
||||
case MSG_REMOVE_DOWNLOAD:
|
||||
id = (String) message.obj;
|
||||
@ -629,34 +626,34 @@ public final class DownloadManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void setManualStopReasonInternal(@Nullable String id, int manualStopReason) {
|
||||
private void setStopReasonInternal(@Nullable String id, int stopReason) {
|
||||
if (id != null) {
|
||||
DownloadInternal downloadInternal = getDownload(id);
|
||||
if (downloadInternal != null) {
|
||||
logd("download manual stop reason is set to : " + manualStopReason, downloadInternal);
|
||||
downloadInternal.setManualStopReason(manualStopReason);
|
||||
logd("download stop reason is set to : " + stopReason, downloadInternal);
|
||||
downloadInternal.setStopReason(stopReason);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < downloadInternals.size(); i++) {
|
||||
downloadInternals.get(i).setManualStopReason(manualStopReason);
|
||||
downloadInternals.get(i).setStopReason(stopReason);
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (id != null) {
|
||||
downloadIndex.setManualStopReason(id, manualStopReason);
|
||||
downloadIndex.setStopReason(id, stopReason);
|
||||
} else {
|
||||
downloadIndex.setManualStopReason(manualStopReason);
|
||||
downloadIndex.setStopReason(stopReason);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "setManualStopReason failed", e);
|
||||
Log.e(TAG, "setStopReason failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void addDownloadInternal(DownloadRequest request, int manualStopReason) {
|
||||
private void addDownloadInternal(DownloadRequest request, int stopReason) {
|
||||
DownloadInternal downloadInternal = getDownload(request.id);
|
||||
if (downloadInternal != null) {
|
||||
downloadInternal.addRequest(request, manualStopReason);
|
||||
downloadInternal.addRequest(request, stopReason);
|
||||
logd("Request is added to existing download", downloadInternal);
|
||||
} else {
|
||||
Download download = loadDownload(request.id);
|
||||
@ -665,14 +662,14 @@ public final class DownloadManager {
|
||||
download =
|
||||
new Download(
|
||||
request,
|
||||
manualStopReason != Download.MANUAL_STOP_REASON_NONE ? STATE_STOPPED : STATE_QUEUED,
|
||||
stopReason != Download.STOP_REASON_NONE ? STATE_STOPPED : STATE_QUEUED,
|
||||
Download.FAILURE_REASON_NONE,
|
||||
manualStopReason,
|
||||
stopReason,
|
||||
/* startTimeMs= */ nowMs,
|
||||
/* updateTimeMs= */ nowMs);
|
||||
logd("Download state is created for " + request.id);
|
||||
} else {
|
||||
download = mergeRequest(download, request, manualStopReason);
|
||||
download = mergeRequest(download, request, stopReason);
|
||||
logd("Download state is loaded for " + request.id);
|
||||
}
|
||||
addDownloadForState(download);
|
||||
@ -820,11 +817,11 @@ public final class DownloadManager {
|
||||
}
|
||||
|
||||
/* package */ static Download mergeRequest(
|
||||
Download download, DownloadRequest request, int manualStopReason) {
|
||||
Download download, DownloadRequest request, int stopReason) {
|
||||
@Download.State int state = download.state;
|
||||
if (state == STATE_REMOVING || state == STATE_RESTARTING) {
|
||||
state = STATE_RESTARTING;
|
||||
} else if (manualStopReason != MANUAL_STOP_REASON_NONE) {
|
||||
} else if (stopReason != STOP_REASON_NONE) {
|
||||
state = STATE_STOPPED;
|
||||
} else {
|
||||
state = STATE_QUEUED;
|
||||
@ -835,7 +832,7 @@ public final class DownloadManager {
|
||||
download.request.copyWithMergedRequest(request),
|
||||
state,
|
||||
FAILURE_REASON_NONE,
|
||||
manualStopReason,
|
||||
stopReason,
|
||||
startTimeMs,
|
||||
/* updateTimeMs= */ nowMs,
|
||||
download.counters);
|
||||
@ -846,7 +843,7 @@ public final class DownloadManager {
|
||||
download.request,
|
||||
state,
|
||||
FAILURE_REASON_NONE,
|
||||
download.manualStopReason,
|
||||
download.stopReason,
|
||||
download.startTimeMs,
|
||||
/* updateTimeMs= */ System.currentTimeMillis(),
|
||||
download.counters);
|
||||
@ -882,21 +879,21 @@ public final class DownloadManager {
|
||||
|
||||
// TODO: Get rid of these and use download directly.
|
||||
@Download.State private int state;
|
||||
private int manualStopReason;
|
||||
private int stopReason;
|
||||
@MonotonicNonNull @Download.FailureReason private int failureReason;
|
||||
|
||||
private DownloadInternal(DownloadManager downloadManager, Download download) {
|
||||
this.downloadManager = downloadManager;
|
||||
this.download = download;
|
||||
manualStopReason = download.manualStopReason;
|
||||
stopReason = download.stopReason;
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
initialize(download.state);
|
||||
}
|
||||
|
||||
public void addRequest(DownloadRequest newRequest, int manualStopReason) {
|
||||
download = mergeRequest(download, newRequest, manualStopReason);
|
||||
public void addRequest(DownloadRequest newRequest, int stopReason) {
|
||||
download = mergeRequest(download, newRequest, stopReason);
|
||||
initialize();
|
||||
}
|
||||
|
||||
@ -910,7 +907,7 @@ public final class DownloadManager {
|
||||
download.request,
|
||||
state,
|
||||
state != STATE_FAILED ? FAILURE_REASON_NONE : failureReason,
|
||||
manualStopReason,
|
||||
stopReason,
|
||||
download.startTimeMs,
|
||||
/* updateTimeMs= */ System.currentTimeMillis(),
|
||||
download.counters);
|
||||
@ -934,8 +931,8 @@ public final class DownloadManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void setManualStopReason(int manualStopReason) {
|
||||
this.manualStopReason = manualStopReason;
|
||||
public void setStopReason(int stopReason) {
|
||||
this.stopReason = stopReason;
|
||||
updateStopState();
|
||||
}
|
||||
|
||||
@ -981,7 +978,7 @@ public final class DownloadManager {
|
||||
}
|
||||
|
||||
private boolean canStart() {
|
||||
return downloadManager.canStartDownloads() && manualStopReason == MANUAL_STOP_REASON_NONE;
|
||||
return downloadManager.canStartDownloads() && stopReason == STOP_REASON_NONE;
|
||||
}
|
||||
|
||||
private void startOrQueue() {
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package com.google.android.exoplayer2.offline;
|
||||
|
||||
import static com.google.android.exoplayer2.offline.Download.MANUAL_STOP_REASON_NONE;
|
||||
import static com.google.android.exoplayer2.offline.Download.STOP_REASON_NONE;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.Service;
|
||||
@ -58,16 +58,15 @@ public abstract class DownloadService extends Service {
|
||||
* <ul>
|
||||
* <li>{@link #KEY_DOWNLOAD_REQUEST} - A {@link DownloadRequest} defining the download to be
|
||||
* added.
|
||||
* <li>{@link #KEY_MANUAL_STOP_REASON} - An initial manual stop reason for the download. If
|
||||
* omitted {@link Download#MANUAL_STOP_REASON_NONE} is used.
|
||||
* <li>{@link #KEY_STOP_REASON} - An initial stop reason for the download. If omitted {@link
|
||||
* Download#STOP_REASON_NONE} is used.
|
||||
* <li>{@link #KEY_FOREGROUND} - See {@link #KEY_FOREGROUND}.
|
||||
* </ul>
|
||||
*/
|
||||
public static final String ACTION_ADD = "com.google.android.exoplayer.downloadService.action.ADD";
|
||||
|
||||
/**
|
||||
* Starts all downloads except those that are manually stopped (i.e. have a non-zero {@link
|
||||
* Download#manualStopReason}). Extras:
|
||||
* Starts all downloads except those that have a non-zero {@link Download#stopReason}. Extras:
|
||||
*
|
||||
* <ul>
|
||||
* <li>{@link #KEY_FOREGROUND} - See {@link #KEY_FOREGROUND}.
|
||||
@ -87,19 +86,18 @@ public abstract class DownloadService extends Service {
|
||||
"com.google.android.exoplayer.downloadService.action.STOP";
|
||||
|
||||
/**
|
||||
* Sets the manual stop reason for one or all downloads. To clear the manual stop reason, pass
|
||||
* {@link Download#MANUAL_STOP_REASON_NONE}. Extras:
|
||||
* Sets the stop reason for one or all downloads. To clear the stop reason, pass {@link
|
||||
* Download#STOP_REASON_NONE}. Extras:
|
||||
*
|
||||
* <ul>
|
||||
* <li>{@link #KEY_CONTENT_ID} - The content id of a single download to update with the manual
|
||||
* stop reason. If omitted, all downloads will be updated.
|
||||
* <li>{@link #KEY_MANUAL_STOP_REASON} - An application provided reason for stopping the
|
||||
* download or downloads, or {@link Download#MANUAL_STOP_REASON_NONE} to clear the manual
|
||||
* stop reason.
|
||||
* <li>{@link #KEY_STOP_REASON} - An application provided reason for stopping the download or
|
||||
* downloads, or {@link Download#STOP_REASON_NONE} to clear the manual stop reason.
|
||||
* <li>{@link #KEY_FOREGROUND} - See {@link #KEY_FOREGROUND}.
|
||||
* </ul>
|
||||
*/
|
||||
public static final String ACTION_SET_MANUAL_STOP_REASON =
|
||||
public static final String ACTION_SET_STOP_REASON =
|
||||
"com.google.android.exoplayer.downloadService.action.SET_MANUAL_STOP_REASON";
|
||||
|
||||
/**
|
||||
@ -117,16 +115,12 @@ public abstract class DownloadService extends Service {
|
||||
public static final String KEY_DOWNLOAD_REQUEST = "download_request";
|
||||
|
||||
/**
|
||||
* Key for the content id in {@link #ACTION_SET_MANUAL_STOP_REASON} and {@link #ACTION_REMOVE}
|
||||
* intents.
|
||||
* Key for the content id in {@link #ACTION_SET_STOP_REASON} and {@link #ACTION_REMOVE} intents.
|
||||
*/
|
||||
public static final String KEY_CONTENT_ID = "content_id";
|
||||
|
||||
/**
|
||||
* Key for the manual stop reason in {@link #ACTION_SET_MANUAL_STOP_REASON} and {@link
|
||||
* #ACTION_ADD} intents.
|
||||
*/
|
||||
public static final String KEY_MANUAL_STOP_REASON = "manual_stop_reason";
|
||||
/** Key for the stop reason in {@link #ACTION_SET_STOP_REASON} and {@link #ACTION_ADD} intents. */
|
||||
public static final String KEY_STOP_REASON = "manual_stop_reason";
|
||||
|
||||
/**
|
||||
* Key for a boolean extra that can be set on any intent to indicate whether the service was
|
||||
@ -244,8 +238,7 @@ public abstract class DownloadService extends Service {
|
||||
Class<? extends DownloadService> clazz,
|
||||
DownloadRequest downloadRequest,
|
||||
boolean foreground) {
|
||||
return buildAddRequestIntent(
|
||||
context, clazz, downloadRequest, MANUAL_STOP_REASON_NONE, foreground);
|
||||
return buildAddRequestIntent(context, clazz, downloadRequest, STOP_REASON_NONE, foreground);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -254,8 +247,8 @@ public abstract class DownloadService extends Service {
|
||||
* @param context A {@link Context}.
|
||||
* @param clazz The concrete download service being targeted by the intent.
|
||||
* @param downloadRequest The request to be executed.
|
||||
* @param manualStopReason An initial manual stop reason for the download, or {@link
|
||||
* Download#MANUAL_STOP_REASON_NONE} if the download should be started.
|
||||
* @param stopReason An initial stop reason for the download, or {@link Download#STOP_REASON_NONE}
|
||||
* if the download should be started.
|
||||
* @param foreground Whether this intent will be used to start the service in the foreground.
|
||||
* @return Created Intent.
|
||||
*/
|
||||
@ -263,11 +256,11 @@ public abstract class DownloadService extends Service {
|
||||
Context context,
|
||||
Class<? extends DownloadService> clazz,
|
||||
DownloadRequest downloadRequest,
|
||||
int manualStopReason,
|
||||
int stopReason,
|
||||
boolean foreground) {
|
||||
return getIntent(context, clazz, ACTION_ADD, foreground)
|
||||
.putExtra(KEY_DOWNLOAD_REQUEST, downloadRequest)
|
||||
.putExtra(KEY_MANUAL_STOP_REASON, manualStopReason);
|
||||
.putExtra(KEY_STOP_REASON, stopReason);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -285,25 +278,25 @@ public abstract class DownloadService extends Service {
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an {@link Intent} for setting the manual stop reason for one or all downloads. To clear
|
||||
* the manual stop reason, pass {@link Download#MANUAL_STOP_REASON_NONE}.
|
||||
* Builds an {@link Intent} for setting the stop reason for one or all downloads. To clear the
|
||||
* stop reason, pass {@link Download#STOP_REASON_NONE}.
|
||||
*
|
||||
* @param context A {@link Context}.
|
||||
* @param clazz The concrete download service being targeted by the intent.
|
||||
* @param id The content id, or {@code null} to set the manual stop reason for all downloads.
|
||||
* @param manualStopReason An application defined stop reason.
|
||||
* @param id The content id, or {@code null} to set the stop reason for all downloads.
|
||||
* @param stopReason An application defined stop reason.
|
||||
* @param foreground Whether this intent will be used to start the service in the foreground.
|
||||
* @return Created Intent.
|
||||
*/
|
||||
public static Intent buildSetManualStopReasonIntent(
|
||||
public static Intent buildSetStopReasonIntent(
|
||||
Context context,
|
||||
Class<? extends DownloadService> clazz,
|
||||
@Nullable String id,
|
||||
int manualStopReason,
|
||||
int stopReason,
|
||||
boolean foreground) {
|
||||
return getIntent(context, clazz, ACTION_SET_MANUAL_STOP_REASON, foreground)
|
||||
return getIntent(context, clazz, ACTION_SET_STOP_REASON, foreground)
|
||||
.putExtra(KEY_CONTENT_ID, id)
|
||||
.putExtra(KEY_MANUAL_STOP_REASON, manualStopReason);
|
||||
.putExtra(KEY_STOP_REASON, stopReason);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -364,23 +357,22 @@ public abstract class DownloadService extends Service {
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the service if not started already and sets the manual stop reason for one or all
|
||||
* downloads. To clear manual stop reason, pass {@link Download#MANUAL_STOP_REASON_NONE}.
|
||||
* Starts the service if not started already and sets the stop reason for one or all downloads. To
|
||||
* clear stop reason, pass {@link Download#STOP_REASON_NONE}.
|
||||
*
|
||||
* @param context A {@link Context}.
|
||||
* @param clazz The concrete download service to be started.
|
||||
* @param id The content id, or {@code null} to set the manual stop reason for all downloads.
|
||||
* @param manualStopReason An application defined stop reason.
|
||||
* @param id The content id, or {@code null} to set the stop reason for all downloads.
|
||||
* @param stopReason An application defined stop reason.
|
||||
* @param foreground Whether the service is started in the foreground.
|
||||
*/
|
||||
public static void sendManualStopReason(
|
||||
public static void sendStopReason(
|
||||
Context context,
|
||||
Class<? extends DownloadService> clazz,
|
||||
@Nullable String id,
|
||||
int manualStopReason,
|
||||
int stopReason,
|
||||
boolean foreground) {
|
||||
Intent intent =
|
||||
buildSetManualStopReasonIntent(context, clazz, id, manualStopReason, foreground);
|
||||
Intent intent = buildSetStopReasonIntent(context, clazz, id, stopReason, foreground);
|
||||
startService(context, intent, foreground);
|
||||
}
|
||||
|
||||
@ -481,9 +473,8 @@ public abstract class DownloadService extends Service {
|
||||
if (downloadRequest == null) {
|
||||
Log.e(TAG, "Ignored ADD: Missing " + KEY_DOWNLOAD_REQUEST + " extra");
|
||||
} else {
|
||||
int manualStopReason =
|
||||
intent.getIntExtra(KEY_MANUAL_STOP_REASON, Download.MANUAL_STOP_REASON_NONE);
|
||||
downloadManager.addDownload(downloadRequest, manualStopReason);
|
||||
int stopReason = intent.getIntExtra(KEY_STOP_REASON, Download.STOP_REASON_NONE);
|
||||
downloadManager.addDownload(downloadRequest, stopReason);
|
||||
}
|
||||
break;
|
||||
case ACTION_START:
|
||||
@ -492,15 +483,13 @@ public abstract class DownloadService extends Service {
|
||||
case ACTION_STOP:
|
||||
downloadManager.stopDownloads();
|
||||
break;
|
||||
case ACTION_SET_MANUAL_STOP_REASON:
|
||||
if (!intent.hasExtra(KEY_MANUAL_STOP_REASON)) {
|
||||
Log.e(
|
||||
TAG, "Ignored SET_MANUAL_STOP_REASON: Missing " + KEY_MANUAL_STOP_REASON + " extra");
|
||||
case ACTION_SET_STOP_REASON:
|
||||
if (!intent.hasExtra(KEY_STOP_REASON)) {
|
||||
Log.e(TAG, "Ignored SET_MANUAL_STOP_REASON: Missing " + KEY_STOP_REASON + " extra");
|
||||
} else {
|
||||
String contentId = intent.getStringExtra(KEY_CONTENT_ID);
|
||||
int manualStopReason =
|
||||
intent.getIntExtra(KEY_MANUAL_STOP_REASON, Download.MANUAL_STOP_REASON_NONE);
|
||||
downloadManager.setManualStopReason(contentId, manualStopReason);
|
||||
int stopReason = intent.getIntExtra(KEY_STOP_REASON, Download.STOP_REASON_NONE);
|
||||
downloadManager.setStopReason(contentId, stopReason);
|
||||
}
|
||||
break;
|
||||
case ACTION_REMOVE:
|
||||
|
@ -36,24 +36,24 @@ public interface WritableDownloadIndex extends DownloadIndex {
|
||||
*/
|
||||
void removeDownload(String id) throws IOException;
|
||||
/**
|
||||
* Sets the manual stop reason of the downloads in a terminal state ({@link
|
||||
* Download#STATE_COMPLETED}, {@link Download#STATE_FAILED}).
|
||||
* Sets the stop reason of the downloads in a terminal state ({@link Download#STATE_COMPLETED},
|
||||
* {@link Download#STATE_FAILED}).
|
||||
*
|
||||
* @param manualStopReason The manual stop reason.
|
||||
* @param stopReason The stop reason.
|
||||
* @throws throws IOException If an error occurs updating the state.
|
||||
*/
|
||||
void setManualStopReason(int manualStopReason) throws IOException;
|
||||
void setStopReason(int stopReason) throws IOException;
|
||||
|
||||
/**
|
||||
* Sets the manual stop reason of the download with the given {@code id} in a terminal state
|
||||
* ({@link Download#STATE_COMPLETED}, {@link Download#STATE_FAILED}).
|
||||
* Sets the stop reason of the download with the given {@code id} in a terminal state ({@link
|
||||
* Download#STATE_COMPLETED}, {@link Download#STATE_FAILED}).
|
||||
*
|
||||
* <p>If there's no {@link Download} with the given {@code id} or it isn't in a terminal state,
|
||||
* then nothing happens.
|
||||
*
|
||||
* @param id ID of a {@link Download}.
|
||||
* @param manualStopReason The manual stop reason.
|
||||
* @param stopReason The stop reason.
|
||||
* @throws throws IOException If an error occurs updating the state.
|
||||
*/
|
||||
void setManualStopReason(String id, int manualStopReason) throws IOException;
|
||||
void setStopReason(String id, int stopReason) throws IOException;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ public class DefaultDownloadIndexTest {
|
||||
.setDownloadedBytes(200)
|
||||
.setTotalBytes(400)
|
||||
.setFailureReason(Download.FAILURE_REASON_UNKNOWN)
|
||||
.setManualStopReason(0x12345678)
|
||||
.setStopReason(0x12345678)
|
||||
.setStartTimeMs(10)
|
||||
.setUpdateTimeMs(20)
|
||||
.setStreamKeys(
|
||||
@ -204,23 +204,22 @@ public class DefaultDownloadIndexTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setManualStopReason_setReasonToNone() throws Exception {
|
||||
public void setStopReason_setReasonToNone() throws Exception {
|
||||
String id = "id";
|
||||
DownloadBuilder downloadBuilder =
|
||||
new DownloadBuilder(id).setState(Download.STATE_COMPLETED).setManualStopReason(0x12345678);
|
||||
new DownloadBuilder(id).setState(Download.STATE_COMPLETED).setStopReason(0x12345678);
|
||||
Download download = downloadBuilder.build();
|
||||
downloadIndex.putDownload(download);
|
||||
|
||||
downloadIndex.setManualStopReason(Download.MANUAL_STOP_REASON_NONE);
|
||||
downloadIndex.setStopReason(Download.STOP_REASON_NONE);
|
||||
|
||||
Download readDownload = downloadIndex.getDownload(id);
|
||||
Download expectedDownload =
|
||||
downloadBuilder.setManualStopReason(Download.MANUAL_STOP_REASON_NONE).build();
|
||||
Download expectedDownload = downloadBuilder.setStopReason(Download.STOP_REASON_NONE).build();
|
||||
assertEqual(readDownload, expectedDownload);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setManualStopReason_setReason() throws Exception {
|
||||
public void setStopReason_setReason() throws Exception {
|
||||
String id = "id";
|
||||
DownloadBuilder downloadBuilder =
|
||||
new DownloadBuilder(id)
|
||||
@ -228,47 +227,46 @@ public class DefaultDownloadIndexTest {
|
||||
.setFailureReason(Download.FAILURE_REASON_UNKNOWN);
|
||||
Download download = downloadBuilder.build();
|
||||
downloadIndex.putDownload(download);
|
||||
int manualStopReason = 0x12345678;
|
||||
int stopReason = 0x12345678;
|
||||
|
||||
downloadIndex.setManualStopReason(manualStopReason);
|
||||
downloadIndex.setStopReason(stopReason);
|
||||
|
||||
Download readDownload = downloadIndex.getDownload(id);
|
||||
Download expectedDownload = downloadBuilder.setManualStopReason(manualStopReason).build();
|
||||
Download expectedDownload = downloadBuilder.setStopReason(stopReason).build();
|
||||
assertEqual(readDownload, expectedDownload);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setManualStopReason_notTerminalState_doesNotSetManualStopReason() throws Exception {
|
||||
public void setStopReason_notTerminalState_doesNotSetStopReason() throws Exception {
|
||||
String id = "id";
|
||||
DownloadBuilder downloadBuilder = new DownloadBuilder(id).setState(Download.STATE_DOWNLOADING);
|
||||
Download download = downloadBuilder.build();
|
||||
downloadIndex.putDownload(download);
|
||||
int notMetRequirements = 0x12345678;
|
||||
|
||||
downloadIndex.setManualStopReason(notMetRequirements);
|
||||
downloadIndex.setStopReason(notMetRequirements);
|
||||
|
||||
Download readDownload = downloadIndex.getDownload(id);
|
||||
assertEqual(readDownload, download);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSingleDownloadManualStopReason_setReasonToNone() throws Exception {
|
||||
public void setSingleDownloadStopReason_setReasonToNone() throws Exception {
|
||||
String id = "id";
|
||||
DownloadBuilder downloadBuilder =
|
||||
new DownloadBuilder(id).setState(Download.STATE_COMPLETED).setManualStopReason(0x12345678);
|
||||
new DownloadBuilder(id).setState(Download.STATE_COMPLETED).setStopReason(0x12345678);
|
||||
Download download = downloadBuilder.build();
|
||||
downloadIndex.putDownload(download);
|
||||
|
||||
downloadIndex.setManualStopReason(id, Download.MANUAL_STOP_REASON_NONE);
|
||||
downloadIndex.setStopReason(id, Download.STOP_REASON_NONE);
|
||||
|
||||
Download readDownload = downloadIndex.getDownload(id);
|
||||
Download expectedDownload =
|
||||
downloadBuilder.setManualStopReason(Download.MANUAL_STOP_REASON_NONE).build();
|
||||
Download expectedDownload = downloadBuilder.setStopReason(Download.STOP_REASON_NONE).build();
|
||||
assertEqual(readDownload, expectedDownload);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSingleDownloadManualStopReason_setReason() throws Exception {
|
||||
public void setSingleDownloadStopReason_setReason() throws Exception {
|
||||
String id = "id";
|
||||
DownloadBuilder downloadBuilder =
|
||||
new DownloadBuilder(id)
|
||||
@ -276,25 +274,24 @@ public class DefaultDownloadIndexTest {
|
||||
.setFailureReason(Download.FAILURE_REASON_UNKNOWN);
|
||||
Download download = downloadBuilder.build();
|
||||
downloadIndex.putDownload(download);
|
||||
int manualStopReason = 0x12345678;
|
||||
int stopReason = 0x12345678;
|
||||
|
||||
downloadIndex.setManualStopReason(id, manualStopReason);
|
||||
downloadIndex.setStopReason(id, stopReason);
|
||||
|
||||
Download readDownload = downloadIndex.getDownload(id);
|
||||
Download expectedDownload = downloadBuilder.setManualStopReason(manualStopReason).build();
|
||||
Download expectedDownload = downloadBuilder.setStopReason(stopReason).build();
|
||||
assertEqual(readDownload, expectedDownload);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSingleDownloadManualStopReason_notTerminalState_doesNotSetManualStopReason()
|
||||
throws Exception {
|
||||
public void setSingleDownloadStopReason_notTerminalState_doesNotSetStopReason() throws Exception {
|
||||
String id = "id";
|
||||
DownloadBuilder downloadBuilder = new DownloadBuilder(id).setState(Download.STATE_DOWNLOADING);
|
||||
Download download = downloadBuilder.build();
|
||||
downloadIndex.putDownload(download);
|
||||
int notMetRequirements = 0x12345678;
|
||||
|
||||
downloadIndex.setManualStopReason(id, notMetRequirements);
|
||||
downloadIndex.setStopReason(id, notMetRequirements);
|
||||
|
||||
Download readDownload = downloadIndex.getDownload(id);
|
||||
assertEqual(readDownload, download);
|
||||
@ -306,7 +303,7 @@ public class DefaultDownloadIndexTest {
|
||||
assertThat(download.startTimeMs).isEqualTo(that.startTimeMs);
|
||||
assertThat(download.updateTimeMs).isEqualTo(that.updateTimeMs);
|
||||
assertThat(download.failureReason).isEqualTo(that.failureReason);
|
||||
assertThat(download.manualStopReason).isEqualTo(that.manualStopReason);
|
||||
assertThat(download.stopReason).isEqualTo(that.stopReason);
|
||||
assertThat(download.getDownloadPercentage()).isEqualTo(that.getDownloadPercentage());
|
||||
assertThat(download.getDownloadedBytes()).isEqualTo(that.getDownloadedBytes());
|
||||
assertThat(download.getTotalBytes()).isEqualTo(that.getTotalBytes());
|
||||
|
@ -37,7 +37,7 @@ class DownloadBuilder {
|
||||
@Nullable private String cacheKey;
|
||||
private int state;
|
||||
private int failureReason;
|
||||
private int manualStopReason;
|
||||
private int stopReason;
|
||||
private long startTimeMs;
|
||||
private long updateTimeMs;
|
||||
private List<StreamKey> streamKeys;
|
||||
@ -127,8 +127,8 @@ class DownloadBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public DownloadBuilder setManualStopReason(int manualStopReason) {
|
||||
this.manualStopReason = manualStopReason;
|
||||
public DownloadBuilder setStopReason(int stopReason) {
|
||||
this.stopReason = stopReason;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -156,6 +156,6 @@ class DownloadBuilder {
|
||||
DownloadRequest request =
|
||||
new DownloadRequest(id, type, uri, streamKeys, cacheKey, customMetadata);
|
||||
return new Download(
|
||||
request, state, failureReason, manualStopReason, startTimeMs, updateTimeMs, counters);
|
||||
request, state, failureReason, stopReason, startTimeMs, updateTimeMs, counters);
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class DownloadManagerTest {
|
||||
private static final int MAX_RETRY_DELAY = 5000;
|
||||
/** Maximum number of times a downloader can be restarted before doing a released check. */
|
||||
private static final int MAX_STARTS_BEFORE_RELEASED = 1;
|
||||
/** A manual stop reason. */
|
||||
/** A stop reason. */
|
||||
private static final int APP_STOP_REASON = 1;
|
||||
/** The minimum number of times a task must be retried before failing. */
|
||||
private static final int MIN_RETRY_COUNT = 3;
|
||||
@ -401,12 +401,11 @@ public class DownloadManagerTest {
|
||||
|
||||
task.assertDownloading();
|
||||
|
||||
runOnMainThread(() -> downloadManager.setManualStopReason(task.taskId, APP_STOP_REASON));
|
||||
runOnMainThread(() -> downloadManager.setStopReason(task.taskId, APP_STOP_REASON));
|
||||
|
||||
task.assertStopped();
|
||||
|
||||
runOnMainThread(
|
||||
() -> downloadManager.setManualStopReason(task.taskId, Download.MANUAL_STOP_REASON_NONE));
|
||||
runOnMainThread(() -> downloadManager.setStopReason(task.taskId, Download.STOP_REASON_NONE));
|
||||
|
||||
runner.getDownloader(1).assertStarted().unblock();
|
||||
|
||||
@ -420,7 +419,7 @@ public class DownloadManagerTest {
|
||||
|
||||
task.assertDownloading();
|
||||
|
||||
runOnMainThread(() -> downloadManager.setManualStopReason(task.taskId, APP_STOP_REASON));
|
||||
runOnMainThread(() -> downloadManager.setStopReason(task.taskId, APP_STOP_REASON));
|
||||
|
||||
task.assertStopped();
|
||||
|
||||
@ -440,8 +439,7 @@ public class DownloadManagerTest {
|
||||
runner1.postDownloadRequest().getTask().assertDownloading();
|
||||
runner2.postDownloadRequest().postRemoveRequest().getTask().assertRemoving();
|
||||
|
||||
runOnMainThread(
|
||||
() -> downloadManager.setManualStopReason(runner1.getTask().taskId, APP_STOP_REASON));
|
||||
runOnMainThread(() -> downloadManager.setStopReason(runner1.getTask().taskId, APP_STOP_REASON));
|
||||
|
||||
runner1.getTask().assertStopped();
|
||||
|
||||
@ -462,7 +460,7 @@ public class DownloadManagerTest {
|
||||
Download download = downloadBuilder.build();
|
||||
|
||||
Download mergedDownload =
|
||||
DownloadManager.mergeRequest(download, downloadRequest, download.manualStopReason);
|
||||
DownloadManager.mergeRequest(download, downloadRequest, download.stopReason);
|
||||
|
||||
Download expectedDownload = downloadBuilder.setState(Download.STATE_RESTARTING).build();
|
||||
assertEqualIgnoringTimeFields(mergedDownload, expectedDownload);
|
||||
@ -478,7 +476,7 @@ public class DownloadManagerTest {
|
||||
Download download = downloadBuilder.build();
|
||||
|
||||
Download mergedDownload =
|
||||
DownloadManager.mergeRequest(download, downloadRequest, download.manualStopReason);
|
||||
DownloadManager.mergeRequest(download, downloadRequest, download.stopReason);
|
||||
|
||||
Download expectedDownload =
|
||||
downloadBuilder
|
||||
@ -494,26 +492,26 @@ public class DownloadManagerTest {
|
||||
DownloadBuilder downloadBuilder =
|
||||
new DownloadBuilder(downloadRequest)
|
||||
.setState(Download.STATE_STOPPED)
|
||||
.setManualStopReason(/* manualStopReason= */ 1);
|
||||
.setStopReason(/* stopReason= */ 1);
|
||||
Download download = downloadBuilder.build();
|
||||
|
||||
Download mergedDownload =
|
||||
DownloadManager.mergeRequest(download, downloadRequest, download.manualStopReason);
|
||||
DownloadManager.mergeRequest(download, downloadRequest, download.stopReason);
|
||||
|
||||
assertEqualIgnoringTimeFields(mergedDownload, download);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeRequest_manualStopReasonSetButNotStopped_becomesStopped() {
|
||||
public void mergeRequest_stopReasonSetButNotStopped_becomesStopped() {
|
||||
DownloadRequest downloadRequest = createDownloadRequest();
|
||||
DownloadBuilder downloadBuilder =
|
||||
new DownloadBuilder(downloadRequest)
|
||||
.setState(Download.STATE_COMPLETED)
|
||||
.setManualStopReason(/* manualStopReason= */ 1);
|
||||
.setStopReason(/* stopReason= */ 1);
|
||||
Download download = downloadBuilder.build();
|
||||
|
||||
Download mergedDownload =
|
||||
DownloadManager.mergeRequest(download, downloadRequest, download.manualStopReason);
|
||||
DownloadManager.mergeRequest(download, downloadRequest, download.stopReason);
|
||||
|
||||
Download expectedDownload = downloadBuilder.setState(Download.STATE_STOPPED).build();
|
||||
assertEqualIgnoringTimeFields(mergedDownload, expectedDownload);
|
||||
@ -560,7 +558,7 @@ public class DownloadManagerTest {
|
||||
assertThat(download.request).isEqualTo(that.request);
|
||||
assertThat(download.state).isEqualTo(that.state);
|
||||
assertThat(download.failureReason).isEqualTo(that.failureReason);
|
||||
assertThat(download.manualStopReason).isEqualTo(that.manualStopReason);
|
||||
assertThat(download.stopReason).isEqualTo(that.stopReason);
|
||||
assertThat(download.getDownloadPercentage()).isEqualTo(that.getDownloadPercentage());
|
||||
assertThat(download.getDownloadedBytes()).isEqualTo(that.getDownloadedBytes());
|
||||
assertThat(download.getTotalBytes()).isEqualTo(that.getTotalBytes());
|
||||
|
Loading…
x
Reference in New Issue
Block a user