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
4bf42bd2
authored
Dec 12, 2018
by
eguven
Committed by
Oliver Woodman
Dec 14, 2018
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Rename TaskState to DownloadState
PiperOrigin-RevId: 225145311
parent
230a798f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
61 additions
and
59 deletions
RELEASENOTES.md
demos/main/src/main/java/com/google/android/exoplayer2/demo/DemoDownloadService.java
demos/main/src/main/java/com/google/android/exoplayer2/demo/DownloadTracker.java
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadManager.java
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadService.java
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadManagerTest.java
library/ui/src/main/java/com/google/android/exoplayer2/ui/DownloadNotificationUtil.java
testutils_robolectric/src/main/java/com/google/android/exoplayer2/testutil/TestDownloadManagerListener.java
RELEASENOTES.md
View file @
4bf42bd2
...
...
@@ -27,6 +27,7 @@
(
[
#5169
](
https://github.com/google/ExoPlayer/issues/5169
)
).
*
DownloadManager:
*
Create only one task for all DownloadActions for the same content.
*
Rename TaskState to DownloadState.
### 2.9.2 ###
...
...
demos/main/src/main/java/com/google/android/exoplayer2/demo/DemoDownloadService.java
View file @
4bf42bd2
...
...
@@ -17,7 +17,7 @@ package com.google.android.exoplayer2.demo;
import
android.app.Notification
;
import
com.google.android.exoplayer2.offline.DownloadManager
;
import
com.google.android.exoplayer2.offline.DownloadManager.
Task
State
;
import
com.google.android.exoplayer2.offline.DownloadManager.
Download
State
;
import
com.google.android.exoplayer2.offline.DownloadService
;
import
com.google.android.exoplayer2.scheduler.PlatformScheduler
;
import
com.google.android.exoplayer2.ui.DownloadNotificationUtil
;
...
...
@@ -50,40 +50,40 @@ public class DemoDownloadService extends DownloadService {
}
@Override
protected
Notification
getForegroundNotification
(
TaskState
[]
task
States
)
{
protected
Notification
getForegroundNotification
(
DownloadState
[]
download
States
)
{
return
DownloadNotificationUtil
.
buildProgressNotification
(
/* context= */
this
,
R
.
drawable
.
ic_download
,
CHANNEL_ID
,
/* contentIntent= */
null
,
/* message= */
null
,
task
States
);
download
States
);
}
@Override
protected
void
on
TaskStateChanged
(
TaskState
task
State
)
{
if
(
task
State
.
action
.
isRemoveAction
)
{
protected
void
on
DownloadStateChanged
(
DownloadState
download
State
)
{
if
(
download
State
.
action
.
isRemoveAction
)
{
return
;
}
Notification
notification
=
null
;
if
(
taskState
.
state
==
Task
State
.
STATE_COMPLETED
)
{
if
(
downloadState
.
state
==
Download
State
.
STATE_COMPLETED
)
{
notification
=
DownloadNotificationUtil
.
buildDownloadCompletedNotification
(
/* context= */
this
,
R
.
drawable
.
ic_download_done
,
CHANNEL_ID
,
/* contentIntent= */
null
,
Util
.
fromUtf8Bytes
(
task
State
.
action
.
data
));
}
else
if
(
taskState
.
state
==
Task
State
.
STATE_FAILED
)
{
Util
.
fromUtf8Bytes
(
download
State
.
action
.
data
));
}
else
if
(
downloadState
.
state
==
Download
State
.
STATE_FAILED
)
{
notification
=
DownloadNotificationUtil
.
buildDownloadFailedNotification
(
/* context= */
this
,
R
.
drawable
.
ic_download_done
,
CHANNEL_ID
,
/* contentIntent= */
null
,
Util
.
fromUtf8Bytes
(
task
State
.
action
.
data
));
Util
.
fromUtf8Bytes
(
download
State
.
action
.
data
));
}
int
notificationId
=
FOREGROUND_NOTIFICATION_ID
+
1
+
taskState
.
taskI
d
;
int
notificationId
=
FOREGROUND_NOTIFICATION_ID
+
1
+
downloadState
.
i
d
;
NotificationUtil
.
setNotification
(
this
,
notificationId
,
notification
);
}
}
demos/main/src/main/java/com/google/android/exoplayer2/demo/DownloadTracker.java
View file @
4bf42bd2
...
...
@@ -37,7 +37,7 @@ import com.google.android.exoplayer2.offline.ActionFile;
import
com.google.android.exoplayer2.offline.DownloadAction
;
import
com.google.android.exoplayer2.offline.DownloadHelper
;
import
com.google.android.exoplayer2.offline.DownloadManager
;
import
com.google.android.exoplayer2.offline.DownloadManager.
Task
State
;
import
com.google.android.exoplayer2.offline.DownloadManager.
Download
State
;
import
com.google.android.exoplayer2.offline.DownloadService
;
import
com.google.android.exoplayer2.offline.ProgressiveDownloadHelper
;
import
com.google.android.exoplayer2.offline.StreamKey
;
...
...
@@ -144,11 +144,11 @@ public class DownloadTracker implements DownloadManager.Listener {
}
@Override
public
void
on
TaskStateChanged
(
DownloadManager
downloadManager
,
TaskState
task
State
)
{
DownloadAction
action
=
task
State
.
action
;
public
void
on
DownloadStateChanged
(
DownloadManager
downloadManager
,
DownloadState
download
State
)
{
DownloadAction
action
=
download
State
.
action
;
Uri
uri
=
action
.
uri
;
if
((
action
.
isRemoveAction
&&
taskState
.
state
==
Task
State
.
STATE_COMPLETED
)
||
(!
action
.
isRemoveAction
&&
taskState
.
state
==
Task
State
.
STATE_FAILED
))
{
if
((
action
.
isRemoveAction
&&
downloadState
.
state
==
Download
State
.
STATE_COMPLETED
)
||
(!
action
.
isRemoveAction
&&
downloadState
.
state
==
Download
State
.
STATE_FAILED
))
{
// A download has been removed, or has failed. Stop tracking it.
if
(
trackedDownloadStates
.
remove
(
uri
)
!=
null
)
{
handleTrackedDownloadStatesChanged
();
...
...
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadManager.java
View file @
4bf42bd2
This diff is collapsed.
Click to expand it.
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadService.java
View file @
4bf42bd2
...
...
@@ -24,7 +24,7 @@ import android.os.IBinder;
import
android.os.Looper
;
import
android.support.annotation.Nullable
;
import
android.support.annotation.StringRes
;
import
com.google.android.exoplayer2.offline.DownloadManager.
Task
State
;
import
com.google.android.exoplayer2.offline.DownloadManager.
Download
State
;
import
com.google.android.exoplayer2.scheduler.Requirements
;
import
com.google.android.exoplayer2.scheduler.RequirementsWatcher
;
import
com.google.android.exoplayer2.scheduler.Scheduler
;
...
...
@@ -71,9 +71,9 @@ public abstract class DownloadService extends Service {
private
static
final
String
TAG
=
"DownloadService"
;
private
static
final
boolean
DEBUG
=
false
;
// Keep the requirements helper for each DownloadService as long as there are
task
s (and the
// process is running). This allows
tasks to resume when there's no scheduler. It may also allow
//
task
s the resume more quickly than when relying on the scheduler alone.
// Keep the requirements helper for each DownloadService as long as there are
download
s (and the
// process is running). This allows
downloads to resume when there's no scheduler. It may also
//
allow download
s the resume more quickly than when relying on the scheduler alone.
private
static
final
HashMap
<
Class
<?
extends
DownloadService
>,
RequirementsHelper
>
requirementsHelpers
=
new
HashMap
<>();
private
static
final
Requirements
DEFAULT_REQUIREMENTS
=
...
...
@@ -99,7 +99,7 @@ public abstract class DownloadService extends Service {
* <p>If {@code foregroundNotificationId} isn't {@link #FOREGROUND_NOTIFICATION_ID_NONE} (value
* {@value #FOREGROUND_NOTIFICATION_ID_NONE}) the service runs in the foreground with {@link
* #DEFAULT_FOREGROUND_NOTIFICATION_UPDATE_INTERVAL}. In that case {@link
* #getForegroundNotification(
Task
State[])} should be overridden in the subclass.
* #getForegroundNotification(
Download
State[])} should be overridden in the subclass.
*
* @param foregroundNotificationId The notification id for the foreground notification, or {@link
* #FOREGROUND_NOTIFICATION_ID_NONE} (value {@value #FOREGROUND_NOTIFICATION_ID_NONE})
...
...
@@ -110,7 +110,7 @@ public abstract class DownloadService extends Service {
/**
* Creates a DownloadService which will run in the foreground. {@link
* #getForegroundNotification(
Task
State[])} should be overridden in the subclass.
* #getForegroundNotification(
Download
State[])} should be overridden in the subclass.
*
* @param foregroundNotificationId The notification id for the foreground notification, must not
* be 0.
...
...
@@ -128,7 +128,7 @@ public abstract class DownloadService extends Service {
/**
* Creates a DownloadService which will run in the foreground. {@link
* #getForegroundNotification(
Task
State[])} should be overridden in the subclass.
* #getForegroundNotification(
Download
State[])} should be overridden in the subclass.
*
* @param foregroundNotificationId The notification id for the foreground notification. Must not
* be 0.
...
...
@@ -338,29 +338,29 @@ public abstract class DownloadService extends Service {
*
* <p>Returns a notification to be displayed when this service running in the foreground.
*
* <p>This method is called when there is a
task
state change and periodically while there are
* active
task
s. The periodic update interval can be set using {@link #DownloadService(int,
* <p>This method is called when there is a
download
state change and periodically while there are
* active
download
s. The periodic update interval can be set using {@link #DownloadService(int,
* long)}.
*
* <p>On API level 26 and above, this method may also be called just before the service stops,
* with an empty {@code
task
States} array. The returned notification is used to satisfy system
* with an empty {@code
download
States} array. The returned notification is used to satisfy system
* requirements for foreground services.
*
* @param
taskStates The states of all current task
s.
* @param
downloadStates The states of all current download
s.
* @return The foreground notification to display.
*/
protected
Notification
getForegroundNotification
(
TaskState
[]
task
States
)
{
protected
Notification
getForegroundNotification
(
DownloadState
[]
download
States
)
{
throw
new
IllegalStateException
(
getClass
().
getName
()
+
" is started in the foreground but getForegroundNotification() is not implemented."
);
}
/**
* Called when the state of a
task
changes.
* Called when the state of a
download
changes.
*
* @param
taskState The state of the task
.
* @param
downloadState The state of the download
.
*/
protected
void
on
TaskStateChanged
(
TaskState
task
State
)
{
protected
void
on
DownloadStateChanged
(
DownloadState
download
State
)
{
// Do nothing.
}
...
...
@@ -428,10 +428,11 @@ public abstract class DownloadService extends Service {
}
@Override
public
void
onTaskStateChanged
(
DownloadManager
downloadManager
,
TaskState
taskState
)
{
DownloadService
.
this
.
onTaskStateChanged
(
taskState
);
public
void
onDownloadStateChanged
(
DownloadManager
downloadManager
,
DownloadState
downloadState
)
{
DownloadService
.
this
.
onDownloadStateChanged
(
downloadState
);
if
(
foregroundNotificationUpdater
!=
null
)
{
if
(
taskState
.
state
==
Task
State
.
STATE_STARTED
)
{
if
(
downloadState
.
state
==
Download
State
.
STATE_STARTED
)
{
foregroundNotificationUpdater
.
startPeriodicUpdates
();
}
else
{
foregroundNotificationUpdater
.
update
();
...
...
@@ -471,8 +472,8 @@ public abstract class DownloadService extends Service {
}
public
void
update
()
{
TaskState
[]
taskStates
=
downloadManager
.
getAllTask
States
();
startForeground
(
notificationId
,
getForegroundNotification
(
task
States
));
DownloadState
[]
downloadStates
=
downloadManager
.
getAllDownload
States
();
startForeground
(
notificationId
,
getForegroundNotification
(
download
States
));
notificationDisplayed
=
true
;
if
(
periodicUpdatesStarted
)
{
handler
.
removeCallbacks
(
this
);
...
...
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadManagerTest.java
View file @
4bf42bd2
...
...
@@ -20,8 +20,8 @@ import static org.junit.Assert.fail;
import
android.net.Uri
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.offline.DownloadManager.
Task
State
;
import
com.google.android.exoplayer2.offline.DownloadManager.
Task
State.State
;
import
com.google.android.exoplayer2.offline.DownloadManager.
Download
State
;
import
com.google.android.exoplayer2.offline.DownloadManager.
Download
State.State
;
import
com.google.android.exoplayer2.testutil.DummyMainThread
;
import
com.google.android.exoplayer2.testutil.RobolectricUtil
;
import
com.google.android.exoplayer2.testutil.TestDownloadManagerListener
;
...
...
@@ -371,11 +371,11 @@ public class DownloadManagerTest {
TaskWrapper
task2
=
new
DownloadRunner
(
uri2
).
postDownloadAction
().
getTask
();
TaskWrapper
task3
=
new
DownloadRunner
(
uri3
).
postRemoveAction
().
getTask
();
TaskState
[]
states
=
downloadManager
.
getAllTask
States
();
DownloadState
[]
states
=
downloadManager
.
getAllDownload
States
();
assertThat
(
states
).
hasLength
(
3
);
int
[]
taskIds
=
{
task1
.
taskId
,
task2
.
taskId
,
task3
.
taskId
};
int
[]
stateTaskIds
=
{
states
[
0
].
taskId
,
states
[
1
].
taskId
,
states
[
2
].
taskI
d
};
int
[]
stateTaskIds
=
{
states
[
0
].
id
,
states
[
1
].
id
,
states
[
2
].
i
d
};
assertThat
(
stateTaskIds
).
isEqualTo
(
taskIds
);
}
...
...
@@ -522,19 +522,19 @@ public class DownloadManagerTest {
}
private
TaskWrapper
assertStarted
()
throws
InterruptedException
{
return
assertState
(
Task
State
.
STATE_STARTED
);
return
assertState
(
Download
State
.
STATE_STARTED
);
}
private
TaskWrapper
assertCompleted
()
{
return
assertState
(
Task
State
.
STATE_COMPLETED
);
return
assertState
(
Download
State
.
STATE_COMPLETED
);
}
private
TaskWrapper
assertFailed
()
{
return
assertState
(
Task
State
.
STATE_FAILED
);
return
assertState
(
Download
State
.
STATE_FAILED
);
}
private
TaskWrapper
assertQueued
()
{
return
assertState
(
Task
State
.
STATE_QUEUED
);
return
assertState
(
Download
State
.
STATE_QUEUED
);
}
private
TaskWrapper
assertState
(
@State
int
expectedState
)
{
...
...
library/ui/src/main/java/com/google/android/exoplayer2/ui/DownloadNotificationUtil.java
View file @
4bf42bd2
...
...
@@ -23,7 +23,7 @@ import android.support.annotation.Nullable;
import
android.support.annotation.StringRes
;
import
android.support.v4.app.NotificationCompat
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.offline.DownloadManager.
Task
State
;
import
com.google.android.exoplayer2.offline.DownloadManager.
Download
State
;
/** Helper for creating download notifications. */
public
final
class
DownloadNotificationUtil
{
...
...
@@ -33,7 +33,7 @@ public final class DownloadNotificationUtil {
private
DownloadNotificationUtil
()
{}
/**
* Returns a progress notification for the given
task
states.
* Returns a progress notification for the given
download
states.
*
* @param context A context for accessing resources.
* @param smallIcon A small icon for the notification.
...
...
@@ -41,7 +41,7 @@ public final class DownloadNotificationUtil {
* above.
* @param contentIntent An optional content intent to send when the notification is clicked.
* @param message An optional message to display on the notification.
* @param
taskStates The task
states.
* @param
downloadStates The download
states.
* @return The notification.
*/
public
static
Notification
buildProgressNotification
(
...
...
@@ -50,28 +50,28 @@ public final class DownloadNotificationUtil {
String
channelId
,
@Nullable
PendingIntent
contentIntent
,
@Nullable
String
message
,
TaskState
[]
task
States
)
{
DownloadState
[]
download
States
)
{
float
totalPercentage
=
0
;
int
downloadTaskCount
=
0
;
boolean
allDownloadPercentagesUnknown
=
true
;
boolean
haveDownloadedBytes
=
false
;
boolean
haveDownloadTasks
=
false
;
boolean
haveRemoveTasks
=
false
;
for
(
TaskState
taskState
:
task
States
)
{
if
(
taskState
.
state
!=
Task
State
.
STATE_STARTED
&&
taskState
.
state
!=
Task
State
.
STATE_COMPLETED
)
{
for
(
DownloadState
downloadState
:
download
States
)
{
if
(
downloadState
.
state
!=
Download
State
.
STATE_STARTED
&&
downloadState
.
state
!=
Download
State
.
STATE_COMPLETED
)
{
continue
;
}
if
(
task
State
.
action
.
isRemoveAction
)
{
if
(
download
State
.
action
.
isRemoveAction
)
{
haveRemoveTasks
=
true
;
continue
;
}
haveDownloadTasks
=
true
;
if
(
task
State
.
downloadPercentage
!=
C
.
PERCENTAGE_UNSET
)
{
if
(
download
State
.
downloadPercentage
!=
C
.
PERCENTAGE_UNSET
)
{
allDownloadPercentagesUnknown
=
false
;
totalPercentage
+=
task
State
.
downloadPercentage
;
totalPercentage
+=
download
State
.
downloadPercentage
;
}
haveDownloadedBytes
|=
task
State
.
downloadedBytes
>
0
;
haveDownloadedBytes
|=
download
State
.
downloadedBytes
>
0
;
downloadTaskCount
++;
}
...
...
testutils_robolectric/src/main/java/com/google/android/exoplayer2/testutil/TestDownloadManagerListener.java
View file @
4bf42bd2
...
...
@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.testutil;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
com.google.android.exoplayer2.offline.DownloadManager
;
import
com.google.android.exoplayer2.offline.DownloadManager.DownloadState
;
import
java.util.HashMap
;
import
java.util.concurrent.ArrayBlockingQueue
;
import
java.util.concurrent.CountDownLatch
;
...
...
@@ -56,12 +57,11 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen
}
@Override
public
void
onTaskStateChanged
(
DownloadManager
downloadManager
,
DownloadManager
.
TaskState
taskState
)
{
if
(
taskState
.
state
==
DownloadManager
.
TaskState
.
STATE_FAILED
&&
downloadError
==
null
)
{
downloadError
=
taskState
.
error
;
public
void
onDownloadStateChanged
(
DownloadManager
downloadManager
,
DownloadState
downloadState
)
{
if
(
downloadState
.
state
==
DownloadState
.
STATE_FAILED
&&
downloadError
==
null
)
{
downloadError
=
downloadState
.
error
;
}
getStateQueue
(
taskState
.
taskId
).
add
(
task
State
.
state
);
getStateQueue
(
downloadState
.
id
).
add
(
download
State
.
state
);
}
@Override
...
...
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