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