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
0b56a038
authored
Jan 08, 2019
by
eguven
Committed by
Oliver Woodman
Jan 08, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Use stop flag to prevent download start when not initialization/released
PiperOrigin-RevId: 228324452
parent
255a34d3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
48 deletions
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadManager.java
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadState.java
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadManager.java
View file @
0b56a038
...
@@ -25,6 +25,7 @@ import static com.google.android.exoplayer2.offline.DownloadState.STATE_REMOVED;
...
@@ -25,6 +25,7 @@ import static com.google.android.exoplayer2.offline.DownloadState.STATE_REMOVED;
import
static
com
.
google
.
android
.
exoplayer2
.
offline
.
DownloadState
.
STATE_REMOVING
;
import
static
com
.
google
.
android
.
exoplayer2
.
offline
.
DownloadState
.
STATE_REMOVING
;
import
static
com
.
google
.
android
.
exoplayer2
.
offline
.
DownloadState
.
STATE_RESTARTING
;
import
static
com
.
google
.
android
.
exoplayer2
.
offline
.
DownloadState
.
STATE_RESTARTING
;
import
static
com
.
google
.
android
.
exoplayer2
.
offline
.
DownloadState
.
STATE_STOPPED
;
import
static
com
.
google
.
android
.
exoplayer2
.
offline
.
DownloadState
.
STATE_STOPPED
;
import
static
com
.
google
.
android
.
exoplayer2
.
offline
.
DownloadState
.
STOP_FLAG_DOWNLOAD_MANAGER_NOT_READY
;
import
static
com
.
google
.
android
.
exoplayer2
.
offline
.
DownloadState
.
STOP_FLAG_STOPPED
;
import
static
com
.
google
.
android
.
exoplayer2
.
offline
.
DownloadState
.
STOP_FLAG_STOPPED
;
import
android.os.ConditionVariable
;
import
android.os.ConditionVariable
;
...
@@ -127,7 +128,7 @@ public final class DownloadManager {
...
@@ -127,7 +128,7 @@ public final class DownloadManager {
this
.
downloaderFactory
=
downloaderFactory
;
this
.
downloaderFactory
=
downloaderFactory
;
this
.
maxActiveDownloads
=
maxSimultaneousDownloads
;
this
.
maxActiveDownloads
=
maxSimultaneousDownloads
;
this
.
minRetryCount
=
minRetryCount
;
this
.
minRetryCount
=
minRetryCount
;
this
.
stickyStopFlags
=
STOP_FLAG_STOPPED
;
this
.
stickyStopFlags
=
STOP_FLAG_STOPPED
|
STOP_FLAG_DOWNLOAD_MANAGER_NOT_READY
;
downloads
=
new
ArrayList
<>();
downloads
=
new
ArrayList
<>();
activeDownloads
=
new
ArrayList
<>();
activeDownloads
=
new
ArrayList
<>();
...
@@ -169,25 +170,31 @@ public final class DownloadManager {
...
@@ -169,25 +170,31 @@ public final class DownloadManager {
/** Starts the downloads. */
/** Starts the downloads. */
public
void
startDownloads
()
{
public
void
startDownloads
()
{
Assertions
.
checkState
(!
released
);
clearStopFlags
(
STOP_FLAG_STOPPED
);
if
(
stickyStopFlags
!=
0
)
{
stickyStopFlags
=
0
;
for
(
int
i
=
0
;
i
<
downloads
.
size
();
i
++)
{
downloads
.
get
(
i
).
clearStopFlags
(
STOP_FLAG_STOPPED
);
}
logd
(
"Downloads are started"
);
}
}
}
/** Stops all of the downloads. Call {@link #startDownloads()} to restart downloads. */
/** Stops all of the downloads. Call {@link #startDownloads()} to restart downloads. */
public
void
stopDownloads
()
{
public
void
stopDownloads
()
{
setStopFlags
(
STOP_FLAG_STOPPED
);
}
private
void
setStopFlags
(
int
flags
)
{
updateStopFlags
(
flags
,
flags
);
}
private
void
clearStopFlags
(
int
flags
)
{
updateStopFlags
(
flags
,
0
);
}
private
void
updateStopFlags
(
int
flags
,
int
values
)
{
Assertions
.
checkState
(!
released
);
Assertions
.
checkState
(!
released
);
if
(
stickyStopFlags
==
0
)
{
int
updatedStickyStopFlags
=
(
values
&
flags
)
|
(
stickyStopFlags
&
~
flags
);
stickyStopFlags
=
STOP_FLAG_STOPPED
;
if
(
stickyStopFlags
!=
updatedStickyStopFlags
)
{
stickyStopFlags
=
updatedStickyStopFlags
;
for
(
int
i
=
0
;
i
<
downloads
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
downloads
.
size
();
i
++)
{
downloads
.
get
(
i
).
setStopFlags
(
STOP_FLAG_STOPPED
);
downloads
.
get
(
i
).
updateStopFlags
(
flags
,
values
);
}
}
logd
(
"Downloads are stopping"
);
logd
Flags
(
"Sticky stop flags are updated"
,
updatedStickyStopFlags
);
}
}
}
}
...
@@ -269,10 +276,8 @@ public final class DownloadManager {
...
@@ -269,10 +276,8 @@ public final class DownloadManager {
if
(
released
)
{
if
(
released
)
{
return
;
return
;
}
}
setStopFlags
(
STOP_FLAG_DOWNLOAD_MANAGER_NOT_READY
);
released
=
true
;
released
=
true
;
for
(
int
i
=
0
;
i
<
downloads
.
size
();
i
++)
{
downloads
.
get
(
i
).
queue
();
}
final
ConditionVariable
fileIOFinishedCondition
=
new
ConditionVariable
();
final
ConditionVariable
fileIOFinishedCondition
=
new
ConditionVariable
();
fileIOHandler
.
post
(
fileIOFinishedCondition:
:
open
);
fileIOHandler
.
post
(
fileIOFinishedCondition:
:
open
);
fileIOFinishedCondition
.
block
();
fileIOFinishedCondition
.
block
();
...
@@ -294,27 +299,14 @@ public final class DownloadManager {
...
@@ -294,27 +299,14 @@ public final class DownloadManager {
logd
(
"Download is added"
,
download
);
logd
(
"Download is added"
,
download
);
}
}
private
void
maybeStartDownloads
()
{
for
(
int
i
=
0
;
i
<
downloads
.
size
();
i
++)
{
maybeStartDownload
(
downloads
.
get
(
i
));
}
}
private
void
maybeStartDownload
(
Download
download
)
{
private
void
maybeStartDownload
(
Download
download
)
{
if
(
initialized
&&
!
released
&&
activeDownloads
.
size
()
<
maxActiveDownloads
)
{
if
(
activeDownloads
.
size
()
<
maxActiveDownloads
)
{
if
(
download
.
start
())
{
if
(
download
.
start
())
{
activeDownloads
.
add
(
download
);
activeDownloads
.
add
(
download
);
}
}
}
}
}
}
private
void
maybeRestartDownload
(
Download
download
)
{
Assertions
.
checkState
(
activeDownloads
.
contains
(
download
));
if
(
initialized
&&
!
released
)
{
download
.
start
();
}
}
private
void
maybeNotifyListenersIdle
()
{
private
void
maybeNotifyListenersIdle
()
{
if
(!
isIdle
())
{
if
(!
isIdle
())
{
return
;
return
;
...
@@ -339,7 +331,9 @@ public final class DownloadManager {
...
@@ -339,7 +331,9 @@ public final class DownloadManager {
saveActions
();
saveActions
();
}
}
if
(
idle
)
{
if
(
idle
)
{
maybeStartDownloads
();
for
(
int
i
=
0
;
i
<
downloads
.
size
();
i
++)
{
maybeStartDownload
(
downloads
.
get
(
i
));
}
maybeNotifyListenersIdle
();
maybeNotifyListenersIdle
();
}
}
}
}
...
@@ -383,7 +377,7 @@ public final class DownloadManager {
...
@@ -383,7 +377,7 @@ public final class DownloadManager {
for
(
Listener
listener
:
listeners
)
{
for
(
Listener
listener
:
listeners
)
{
listener
.
onInitialized
(
DownloadManager
.
this
);
listener
.
onInitialized
(
DownloadManager
.
this
);
}
}
maybeStartDownloads
(
);
clearStopFlags
(
STOP_FLAG_DOWNLOAD_MANAGER_NOT_READY
);
});
});
});
});
}
}
...
@@ -415,8 +409,16 @@ public final class DownloadManager {
...
@@ -415,8 +409,16 @@ public final class DownloadManager {
}
}
private
static
void
logd
(
String
message
,
Download
download
)
{
private
static
void
logd
(
String
message
,
Download
download
)
{
if
(
DEBUG
)
{
logd
(
message
+
": "
+
download
);
logd
(
message
+
": "
+
download
);
}
}
}
private
static
void
logdFlags
(
String
message
,
int
flags
)
{
if
(
DEBUG
)
{
logd
(
message
+
": "
+
Integer
.
toBinaryString
(
flags
));
}
}
private
static
final
class
Download
{
private
static
final
class
Download
{
...
@@ -529,22 +531,16 @@ public final class DownloadManager {
...
@@ -529,22 +531,16 @@ public final class DownloadManager {
return
true
;
return
true
;
}
}
public
void
setStopFlags
(
int
stopFlags
)
{
public
void
setStopFlags
(
int
flags
)
{
updateStopFlags
(
stopFlags
,
stopFlags
);
updateStopFlags
(
flags
,
flags
);
}
public
void
clearStopFlags
(
int
stopFlags
)
{
updateStopFlags
(
stopFlags
,
0
);
}
}
public
void
queue
()
{
public
void
clearStopFlags
(
int
flags
)
{
if
(
state
==
STATE_DOWNLOADING
)
{
updateStopFlags
(
flags
,
0
);
stopDownloadThread
();
}
}
}
p
rivate
void
updateStopFlags
(
int
mask
,
int
flag
s
)
{
p
ublic
void
updateStopFlags
(
int
flags
,
int
value
s
)
{
stopFlags
=
(
flags
&
mask
)
|
(
stopFlags
&
~
mask
);
stopFlags
=
(
values
&
flags
)
|
(
stopFlags
&
~
flags
);
if
(
stopFlags
!=
0
)
{
if
(
stopFlags
!=
0
)
{
if
(
state
==
STATE_DOWNLOADING
)
{
if
(
state
==
STATE_DOWNLOADING
)
{
stopDownloadThread
();
stopDownloadThread
();
...
@@ -574,7 +570,7 @@ public final class DownloadManager {
...
@@ -574,7 +570,7 @@ public final class DownloadManager {
// Set to queued state but don't notify listeners until we make sure we can't start now.
// Set to queued state but don't notify listeners until we make sure we can't start now.
state
=
STATE_QUEUED
;
state
=
STATE_QUEUED
;
if
(
restart
)
{
if
(
restart
)
{
downloadManager
.
maybeRestartDownload
(
this
);
start
(
);
}
else
{
}
else
{
downloadManager
.
maybeStartDownload
(
this
);
downloadManager
.
maybeStartDownload
(
this
);
}
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadState.java
View file @
0b56a038
...
@@ -73,15 +73,20 @@ public final class DownloadState {
...
@@ -73,15 +73,20 @@ public final class DownloadState {
/** 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
;
/** Download stop flags. Possible flag value is {@link #STOP_FLAG_STOPPED}. */
/**
* Download stop flags. Possible flag values are {@link #STOP_FLAG_DOWNLOAD_MANAGER_NOT_READY} and
* {@link #STOP_FLAG_STOPPED}.
*/
@Documented
@Documented
@Retention
(
RetentionPolicy
.
SOURCE
)
@Retention
(
RetentionPolicy
.
SOURCE
)
@IntDef
(
@IntDef
(
flag
=
true
,
flag
=
true
,
value
=
{
STOP_FLAG_STOPPED
})
value
=
{
STOP_FLAG_
DOWNLOAD_MANAGER_NOT_READY
,
STOP_FLAG_
STOPPED
})
public
@interface
StopFlags
{}
public
@interface
StopFlags
{}
/** Download can't be started as the manager isn't ready. */
public
static
final
int
STOP_FLAG_DOWNLOAD_MANAGER_NOT_READY
=
1
;
/** All downloads are stopped by the application. */
/** All downloads are stopped by the application. */
public
static
final
int
STOP_FLAG_STOPPED
=
1
;
public
static
final
int
STOP_FLAG_STOPPED
=
1
<<
1
;
/** 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
)
{
...
...
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