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
3b5a53f1
authored
Oct 19, 2022
by
Marc Baechinger
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge pull request #126 from stoyicker:cap_concurrent_remove_tasks
PiperOrigin-RevId: 463792127
parents
bac323d3
28e32072
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
5 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 @
3b5a53f1
...
...
@@ -707,6 +707,7 @@ public final class DownloadManager {
private
int
maxParallelDownloads
;
private
int
minRetryCount
;
private
int
activeDownloadTaskCount
;
private
boolean
hasActiveRemoveTask
;
public
InternalHandler
(
HandlerThread
thread
,
...
...
@@ -1058,6 +1059,10 @@ public final class DownloadManager {
return
;
}
if
(
hasActiveRemoveTask
)
{
return
;
}
// We can start a remove task.
Downloader
downloader
=
downloaderFactory
.
createDownloader
(
download
.
request
);
activeTask
=
...
...
@@ -1069,6 +1074,7 @@ public final class DownloadManager {
minRetryCount
,
/* internalHandler= */
this
);
activeTasks
.
put
(
download
.
request
.
id
,
activeTask
);
hasActiveRemoveTask
=
true
;
activeTask
.
start
();
}
...
...
@@ -1098,7 +1104,9 @@ public final class DownloadManager {
activeTasks
.
remove
(
downloadId
);
boolean
isRemove
=
task
.
isRemove
;
if
(!
isRemove
&&
--
activeDownloadTaskCount
==
0
)
{
if
(
isRemove
)
{
hasActiveRemoveTask
=
false
;
}
else
if
(--
activeDownloadTaskCount
==
0
)
{
removeMessages
(
MSG_UPDATE_PROGRESS
);
}
...
...
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadManagerTest.java
View file @
3b5a53f1
...
...
@@ -283,14 +283,14 @@ public class DownloadManagerTest {
postRemoveAllRequest
();
// Both downloads should be removed.
FakeDownloader
downloader2
=
getDownloaderAt
(
2
);
FakeDownloader
downloader3
=
getDownloaderAt
(
3
);
downloader2
.
assertId
(
ID1
);
downloader3
.
assertId
(
ID2
);
downloader2
.
assertRemoveStarted
();
downloader3
.
assertRemoveStarted
();
downloader2
.
finish
();
downloader3
.
finish
();
assertRemoved
(
ID1
);
FakeDownloader
downloader3
=
getDownloaderAt
(
3
);
downloader3
.
assertId
(
ID2
);
downloader3
.
assertRemoveStarted
();
downloader3
.
finish
();
assertRemoved
(
ID2
);
downloadManagerListener
.
blockUntilIdleAndThrowAnyFailure
();
...
...
@@ -712,6 +712,36 @@ public class DownloadManagerTest {
assertEqualIgnoringUpdateTime
(
mergedDownload
,
expectedDownload
);
}
@Test
public
void
removeRequests_runSequentially
()
throws
Throwable
{
// Trigger two remove requests.
postDownloadRequest
(
ID1
);
getDownloaderAt
(
0
).
finish
();
postDownloadRequest
(
ID2
);
getDownloaderAt
(
1
).
finish
();
postRemoveRequest
(
ID1
);
postRemoveRequest
(
ID2
);
// Assert first remove request is executing, second one is queued.
assertRemoving
(
ID1
);
assertQueued
(
ID2
);
FakeDownloader
downloader2
=
getDownloaderAt
(
2
);
downloader2
.
assertId
(
ID1
);
downloader2
.
assertRemoveStarted
();
downloader2
.
finish
();
assertRemoved
(
ID1
);
// Assert second one is running after first one finished
assertRemoving
(
ID2
);
FakeDownloader
downloader3
=
getDownloaderAt
(
3
);
downloader3
.
assertId
(
ID2
);
downloader3
.
assertRemoveStarted
();
downloader3
.
finish
();
assertRemoved
(
ID2
);
downloadManagerListener
.
blockUntilIdleAndThrowAnyFailure
();
}
private
void
setupDownloadManager
(
int
maxParallelDownloads
)
throws
Exception
{
if
(
downloadManager
!=
null
)
{
releaseDownloadManager
();
...
...
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