Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6f9d33db
authored
Mar 25, 2019
by
eguven
Committed by
Toni
Mar 26, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add DefaultDownloadIndex setManualStopReason variant for single download
PiperOrigin-RevId: 240108843
parent
afd9014b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
1 deletions
library/core/src/main/java/com/google/android/exoplayer2/offline/DefaultDownloadIndex.java
library/core/src/test/java/com/google/android/exoplayer2/offline/DefaultDownloadIndexTest.java
library/core/src/main/java/com/google/android/exoplayer2/offline/DefaultDownloadIndex.java
View file @
6f9d33db
...
...
@@ -220,6 +220,7 @@ public final class DefaultDownloadIndex implements DownloadIndex {
/**
* Removes the {@link DownloadState} with the given {@code id}.
*
* @param id ID of a {@link DownloadState}.
* @throws DatabaseIOException If an error occurs removing the state.
*/
public
void
removeDownloadState
(
String
id
)
throws
DatabaseIOException
{
...
...
@@ -250,6 +251,30 @@ public final class DefaultDownloadIndex implements DownloadIndex {
}
}
/**
* Sets the manual stop reason of the download with the given {@code id} in a terminal state
* ({@link DownloadState#STATE_COMPLETED}, {@link DownloadState#STATE_FAILED}).
*
* <p>If there's no {@link DownloadState} with the given {@code id} or it isn't in a terminal
* state, then nothing happens.
*
* @param id ID of a {@link DownloadState}.
* @param manualStopReason The manual stop reason.
* @throws DatabaseIOException If an error occurs updating the state.
*/
public
void
setManualStopReason
(
String
id
,
int
manualStopReason
)
throws
DatabaseIOException
{
ensureInitialized
();
try
{
ContentValues
values
=
new
ContentValues
();
values
.
put
(
COLUMN_MANUAL_STOP_REASON
,
manualStopReason
);
SQLiteDatabase
writableDatabase
=
databaseProvider
.
getWritableDatabase
();
writableDatabase
.
update
(
TABLE_NAME
,
values
,
WHERE_STATE_TERMINAL
+
" AND "
+
WHERE_ID_EQUALS
,
new
String
[]
{
id
});
}
catch
(
SQLException
e
)
{
throw
new
DatabaseIOException
(
e
);
}
}
private
void
ensureInitialized
()
throws
DatabaseIOException
{
if
(
initialized
)
{
return
;
...
...
library/core/src/test/java/com/google/android/exoplayer2/offline/DefaultDownloadIndexTest.java
View file @
6f9d33db
...
...
@@ -221,7 +221,7 @@ public class DefaultDownloadIndexTest {
}
@Test
public
void
setManualStopReason_set
ToReason
None
()
throws
Exception
{
public
void
setManualStopReason_set
ReasonTo
None
()
throws
Exception
{
String
id
=
"id"
;
DownloadStateBuilder
downloadStateBuilder
=
new
DownloadStateBuilder
(
id
)
...
...
@@ -271,4 +271,57 @@ public class DefaultDownloadIndexTest {
DownloadState
readDownloadState
=
downloadIndex
.
getDownloadState
(
id
);
DownloadStateTest
.
assertEqual
(
readDownloadState
,
downloadState
);
}
@Test
public
void
setSingleDownloadManualStopReason_setReasonToNone
()
throws
Exception
{
String
id
=
"id"
;
DownloadStateBuilder
downloadStateBuilder
=
new
DownloadStateBuilder
(
id
)
.
setState
(
DownloadState
.
STATE_COMPLETED
)
.
setManualStopReason
(
0x12345678
);
DownloadState
downloadState
=
downloadStateBuilder
.
build
();
downloadIndex
.
putDownloadState
(
downloadState
);
downloadIndex
.
setManualStopReason
(
id
,
DownloadState
.
MANUAL_STOP_REASON_NONE
);
DownloadState
readDownloadState
=
downloadIndex
.
getDownloadState
(
id
);
DownloadState
expectedDownloadState
=
downloadStateBuilder
.
setManualStopReason
(
DownloadState
.
MANUAL_STOP_REASON_NONE
).
build
();
DownloadStateTest
.
assertEqual
(
readDownloadState
,
expectedDownloadState
);
}
@Test
public
void
setSingleDownloadManualStopReason_setReason
()
throws
Exception
{
String
id
=
"id"
;
DownloadStateBuilder
downloadStateBuilder
=
new
DownloadStateBuilder
(
id
)
.
setState
(
DownloadState
.
STATE_FAILED
)
.
setFailureReason
(
DownloadState
.
FAILURE_REASON_UNKNOWN
);
DownloadState
downloadState
=
downloadStateBuilder
.
build
();
downloadIndex
.
putDownloadState
(
downloadState
);
int
manualStopReason
=
0x12345678
;
downloadIndex
.
setManualStopReason
(
id
,
manualStopReason
);
DownloadState
readDownloadState
=
downloadIndex
.
getDownloadState
(
id
);
DownloadState
expectedDownloadState
=
downloadStateBuilder
.
setManualStopReason
(
manualStopReason
).
build
();
DownloadStateTest
.
assertEqual
(
readDownloadState
,
expectedDownloadState
);
}
@Test
public
void
setSingleDownloadManualStopReason_notTerminalState_doesNotSetManualStopReason
()
throws
Exception
{
String
id
=
"id"
;
DownloadStateBuilder
downloadStateBuilder
=
new
DownloadStateBuilder
(
id
).
setState
(
DownloadState
.
STATE_DOWNLOADING
);
DownloadState
downloadState
=
downloadStateBuilder
.
build
();
downloadIndex
.
putDownloadState
(
downloadState
);
int
notMetRequirements
=
0x12345678
;
downloadIndex
.
setManualStopReason
(
id
,
notMetRequirements
);
DownloadState
readDownloadState
=
downloadIndex
.
getDownloadState
(
id
);
DownloadStateTest
.
assertEqual
(
readDownloadState
,
downloadState
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment