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
ae5e5f7e
authored
Mar 26, 2019
by
eguven
Committed by
Toni
Mar 29, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Stop using remove DownloadActions in DownloadManager
PiperOrigin-RevId: 240376409
parent
709a712a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
31 deletions
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadManager.java
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadManagerTest.java
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadManager.java
View file @
ae5e5f7e
...
...
@@ -665,7 +665,7 @@ public final class DownloadManager {
}
@StartThreadResults
private
int
startDownloadThread
(
Download
download
,
DownloadAction
action
)
{
private
int
startDownloadThread
(
Download
download
)
{
if
(!
initialized
||
released
)
{
return
START_THREAD_NOT_ALLOWED
;
}
...
...
@@ -675,15 +675,13 @@ public final class DownloadManager {
}
return
START_THREAD_WAIT_REMOVAL_TO_FINISH
;
}
if
(!
action
.
isRemoveAction
)
{
if
(!
download
.
isInRemoveState
()
)
{
if
(
simultaneousDownloads
==
maxSimultaneousDownloads
)
{
return
START_THREAD_TOO_MANY_DOWNLOADS
;
}
simultaneousDownloads
++;
}
Downloader
downloader
=
downloaderFactory
.
createDownloader
(
action
);
DownloadThread
downloadThread
=
new
DownloadThread
(
download
,
downloader
,
action
.
isRemoveAction
);
activeDownloads
.
put
(
download
,
downloadThread
);
activeDownloads
.
put
(
download
,
new
DownloadThread
(
download
));
logd
(
"Download is started"
,
download
);
return
START_THREAD_SUCCEEDED
;
}
...
...
@@ -823,8 +821,8 @@ public final class DownloadManager {
public
void
start
()
{
if
(
state
==
STATE_QUEUED
||
state
==
STATE_DOWNLOADING
)
{
startOrQueue
();
}
else
if
(
state
==
STATE_REMOVING
||
state
==
STATE_RESTARTING
)
{
downloadManager
.
startDownloadThread
(
this
,
getAction
()
);
}
else
if
(
isInRemoveState
()
)
{
downloadManager
.
startDownloadThread
(
this
);
}
}
...
...
@@ -838,6 +836,20 @@ public final class DownloadManager {
updateStopState
();
}
public
DownloadAction
getAction
()
{
Assertions
.
checkState
(
state
!=
STATE_REMOVED
);
return
DownloadAction
.
createDownloadAction
(
downloadState
.
type
,
downloadState
.
uri
,
Arrays
.
asList
(
downloadState
.
streamKeys
),
downloadState
.
cacheKey
,
downloadState
.
customMetadata
);
}
public
boolean
isInRemoveState
()
{
return
state
==
STATE_REMOVING
||
state
==
STATE_RESTARTING
;
}
private
void
updateStopState
()
{
DownloadState
oldDownloadState
=
downloadState
;
if
(
canStart
())
{
...
...
@@ -859,8 +871,8 @@ public final class DownloadManager {
// Don't notify listeners with initial state until we make sure we don't switch to
// another state immediately.
state
=
initialState
;
if
(
state
==
STATE_REMOVING
||
state
==
STATE_RESTARTING
)
{
downloadManager
.
startDownloadThread
(
this
,
getAction
()
);
if
(
isInRemoveState
()
)
{
downloadManager
.
startDownloadThread
(
this
);
}
else
if
(
canStart
())
{
startOrQueue
();
}
else
{
...
...
@@ -876,8 +888,8 @@ public final class DownloadManager {
}
private
void
startOrQueue
()
{
Assertions
.
checkState
(!
(
state
==
STATE_REMOVING
||
state
==
STATE_RESTARTING
));
@StartThreadResults
int
result
=
downloadManager
.
startDownloadThread
(
this
,
getAction
()
);
Assertions
.
checkState
(!
isInRemoveState
(
));
@StartThreadResults
int
result
=
downloadManager
.
startDownloadThread
(
this
);
Assertions
.
checkState
(
result
!=
START_THREAD_WAIT_REMOVAL_TO_FINISH
);
if
(
result
==
START_THREAD_SUCCEEDED
||
result
==
START_THREAD_WAIT_DOWNLOAD_CANCELLATION
)
{
setState
(
STATE_DOWNLOADING
);
...
...
@@ -886,20 +898,6 @@ public final class DownloadManager {
}
}
private
DownloadAction
getAction
()
{
Assertions
.
checkState
(
state
!=
STATE_REMOVED
);
if
(
state
==
STATE_REMOVING
||
state
==
STATE_RESTARTING
)
{
return
DownloadAction
.
createRemoveAction
(
downloadState
.
type
,
downloadState
.
uri
,
downloadState
.
cacheKey
);
}
return
DownloadAction
.
createDownloadAction
(
downloadState
.
type
,
downloadState
.
uri
,
Arrays
.
asList
(
downloadState
.
streamKeys
),
downloadState
.
cacheKey
,
downloadState
.
customMetadata
);
}
private
void
setState
(
@DownloadState
.
State
int
newState
)
{
if
(
state
!=
newState
)
{
state
=
newState
;
...
...
@@ -912,7 +910,7 @@ public final class DownloadManager {
return
;
}
if
(
isCanceled
)
{
downloadManager
.
startDownloadThread
(
this
,
getAction
()
);
downloadManager
.
startDownloadThread
(
this
);
}
else
if
(
state
==
STATE_RESTARTING
)
{
initialize
(
STATE_QUEUED
);
}
else
if
(
state
==
STATE_REMOVING
)
{
...
...
@@ -937,10 +935,10 @@ public final class DownloadManager {
private
final
boolean
isRemoveThread
;
private
volatile
boolean
isCanceled
;
private
DownloadThread
(
Download
download
,
Downloader
downloader
,
boolean
isRemoveThread
)
{
private
DownloadThread
(
Download
download
)
{
this
.
download
=
download
;
this
.
downloader
=
downloader
;
this
.
isRemoveThread
=
isRemoveThread
;
this
.
downloader
=
downloader
Factory
.
createDownloader
(
download
.
getAction
())
;
this
.
isRemoveThread
=
download
.
isInRemoveState
()
;
start
();
}
...
...
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadManagerTest.java
View file @
ae5e5f7e
...
...
@@ -702,7 +702,6 @@ public class DownloadManagerTest {
public
void
download
()
throws
InterruptedException
,
IOException
{
// It's ok to update this directly as no other thread will update it.
startCount
++;
assertThat
(
action
.
isRemoveAction
).
isFalse
();
started
.
countDown
();
block
();
if
(
enableDownloadIOException
)
{
...
...
@@ -721,7 +720,6 @@ public class DownloadManagerTest {
public
void
remove
()
throws
InterruptedException
{
// It's ok to update this directly as no other thread will update it.
startCount
++;
assertThat
(
action
.
isRemoveAction
).
isTrue
();
started
.
countDown
();
block
();
}
...
...
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