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
643e187d
authored
Apr 26, 2019
by
olly
Committed by
Oliver Woodman
Apr 26, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add missing getters and clarify STATE_QUEUED documentation
PiperOrigin-RevId: 245401274
parent
01ad1c1a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
14 deletions
library/core/src/main/java/com/google/android/exoplayer2/offline/Download.java
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadManager.java
library/core/src/main/java/com/google/android/exoplayer2/offline/Download.java
View file @
643e187d
...
...
@@ -43,7 +43,17 @@ public final class Download {
})
public
@interface
State
{}
// 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. A download may be queued because the {@link
* DownloadManager}
*
* <ul>
* <li>Is {@link DownloadManager#getDownloadsPaused() paused}
* <li>Has {@link DownloadManager#getRequirements() Requirements} that are not met
* <li>Has already started {@link DownloadManager#getMaxParallelDownloads()
* maxParallelDownloads}
* </ul>
*/
public
static
final
int
STATE_QUEUED
=
0
;
/** The download is stopped for a specified {@link #stopReason}. */
public
static
final
int
STATE_STOPPED
=
1
;
...
...
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadManager.java
View file @
643e187d
...
...
@@ -130,7 +130,7 @@ public final class DownloadManager {
// Messages posted to the background handler.
private
static
final
int
MSG_INITIALIZE
=
0
;
private
static
final
int
MSG_SET_DOWNLOADS_
RESUM
ED
=
1
;
private
static
final
int
MSG_SET_DOWNLOADS_
PAUS
ED
=
1
;
private
static
final
int
MSG_SET_NOT_MET_REQUIREMENTS
=
2
;
private
static
final
int
MSG_SET_STOP_REASON
=
3
;
private
static
final
int
MSG_ADD_DOWNLOAD
=
4
;
...
...
@@ -178,11 +178,12 @@ public final class DownloadManager {
private
int
activeDownloadCount
;
private
boolean
initialized
;
private
boolean
released
;
private
boolean
downloadsPaused
;
private
RequirementsWatcher
requirementsWatcher
;
// Mutable fields that are accessed on the internal thread.
@Requirements
.
RequirementFlags
private
int
notMetRequirements
;
private
boolean
downloads
Resumed
;
private
boolean
downloads
PausedInternal
;
private
int
parallelDownloads
;
// TODO: Fix these to properly support changes at runtime.
...
...
@@ -221,6 +222,8 @@ public final class DownloadManager {
this
.
downloaderFactory
=
downloaderFactory
;
maxParallelDownloads
=
DEFAULT_MAX_PARALLEL_DOWNLOADS
;
minRetryCount
=
DEFAULT_MIN_RETRY_COUNT
;
downloadsPaused
=
true
;
downloadsPausedInternal
=
true
;
downloadInternals
=
new
ArrayList
<>();
downloads
=
new
ArrayList
<>();
...
...
@@ -306,6 +309,11 @@ public final class DownloadManager {
onRequirementsStateChanged
(
requirementsWatcher
,
notMetRequirements
);
}
/** Returns the maximum number of parallel downloads. */
public
int
getMaxParallelDownloads
()
{
return
maxParallelDownloads
;
}
/**
* Sets the maximum number of parallel downloads.
*
...
...
@@ -317,6 +325,14 @@ public final class DownloadManager {
}
/**
* Returns the minimum number of times that a download will be retried. A download will fail if
* the specified number of retries is exceeded without any progress being made.
*/
public
int
getMinRetryCount
()
{
return
minRetryCount
;
}
/**
* Sets the minimum number of times that a download will be retried. A download will fail if the
* specified number of retries is exceeded without any progress being made.
*
...
...
@@ -341,19 +357,41 @@ public final class DownloadManager {
return
Collections
.
unmodifiableList
(
new
ArrayList
<>(
downloads
));
}
/** Resumes all downloads except those that have a non-zero {@link Download#stopReason}. */
/** Returns whether downloads are currently paused. */
public
boolean
getDownloadsPaused
()
{
return
downloadsPaused
;
}
/**
* Resumes downloads.
*
* <p>If the {@link #setRequirements(Requirements) Requirements} are met up to {@link
* #getMaxParallelDownloads() maxParallelDownloads} will be started, excluding those with non-zero
* {@link Download#stopReason stopReasons}.
*/
public
void
resumeDownloads
()
{
if
(!
downloadsPaused
)
{
return
;
}
downloadsPaused
=
false
;
pendingMessages
++;
internalHandler
.
obtainMessage
(
MSG_SET_DOWNLOADS_
RESUMED
,
/* downloadsResumed */
1
,
/* unused */
0
)
.
obtainMessage
(
MSG_SET_DOWNLOADS_
PAUSED
,
/* downloadsPaused */
0
,
/* unused */
0
)
.
sendToTarget
();
}
/** Pauses all downloads. */
/**
* Pauses downloads. Downloads that would otherwise be making progress transition to {@link
* Download#STATE_QUEUED}.
*/
public
void
pauseDownloads
()
{
if
(
downloadsPaused
)
{
return
;
}
downloadsPaused
=
true
;
pendingMessages
++;
internalHandler
.
obtainMessage
(
MSG_SET_DOWNLOADS_
RESUMED
,
/* downloadsResumed */
0
,
/* unused */
0
)
.
obtainMessage
(
MSG_SET_DOWNLOADS_
PAUSED
,
/* downloadsPaused */
1
,
/* unused */
0
)
.
sendToTarget
();
}
...
...
@@ -536,9 +574,9 @@ public final class DownloadManager {
int
notMetRequirements
=
message
.
arg1
;
initializeInternal
(
notMetRequirements
);
break
;
case
MSG_SET_DOWNLOADS_
RESUM
ED:
boolean
downloads
Resum
ed
=
message
.
arg1
!=
0
;
setDownloads
Resumed
(
downloadsResum
ed
);
case
MSG_SET_DOWNLOADS_
PAUS
ED:
boolean
downloads
Paus
ed
=
message
.
arg1
!=
0
;
setDownloads
PausedInternal
(
downloadsPaus
ed
);
break
;
case
MSG_SET_NOT_MET_REQUIREMENTS:
notMetRequirements
=
message
.
arg1
;
...
...
@@ -604,11 +642,11 @@ public final class DownloadManager {
}
}
private
void
setDownloads
Resumed
(
boolean
downloadsResum
ed
)
{
if
(
this
.
downloads
Resumed
==
downloadsResum
ed
)
{
private
void
setDownloads
PausedInternal
(
boolean
downloadsPaus
ed
)
{
if
(
this
.
downloads
PausedInternal
==
downloadsPaus
ed
)
{
return
;
}
this
.
downloads
Resumed
=
downloadsResum
ed
;
this
.
downloads
PausedInternal
=
downloadsPaus
ed
;
for
(
int
i
=
0
;
i
<
downloadInternals
.
size
();
i
++)
{
downloadInternals
.
get
(
i
).
updateStopState
();
}
...
...
@@ -820,7 +858,7 @@ public final class DownloadManager {
}
private
boolean
canStartDownloads
()
{
return
downloadsResumed
&&
notMetRequirements
==
0
;
return
!
downloadsPausedInternal
&&
notMetRequirements
==
0
;
}
/* package */
static
Download
mergeRequest
(
...
...
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