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
ba915017
authored
Apr 15, 2019
by
eguven
Committed by
AquilesCanta
Apr 16, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add DownloadService.invalidateForegroundNotification
ISSUE: #4563 PiperOrigin-RevId: 243616444
parent
18dd3fdb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
16 deletions
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadService.java
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadService.java
View file @
ba915017
...
...
@@ -159,6 +159,7 @@ public abstract class DownloadService extends Service {
private
int
lastStartId
;
private
boolean
startedInForeground
;
private
boolean
taskRemoved
;
private
boolean
isDestroyed
;
/**
* Creates a DownloadService.
...
...
@@ -468,6 +469,7 @@ public abstract class DownloadService extends Service {
@Override
public
void
onDestroy
()
{
logd
(
"onDestroy"
);
isDestroyed
=
true
;
DownloadManagerHelper
downloadManagerHelper
=
downloadManagerListeners
.
get
(
getClass
());
boolean
unschedule
=
!
downloadManager
.
isWaitingForRequirements
();
downloadManagerHelper
.
detachService
(
this
,
unschedule
);
...
...
@@ -518,6 +520,16 @@ public abstract class DownloadService extends Service {
protected
abstract
Notification
getForegroundNotification
(
Download
[]
downloads
);
/**
* Invalidates the current foreground notification and causes {@link
* #getForegroundNotification(Download[])} to be invoked again if the service isn't stopped.
*/
protected
final
void
invalidateForegroundNotification
()
{
if
(
foregroundNotificationUpdater
!=
null
&&
!
isDestroyed
)
{
foregroundNotificationUpdater
.
invalidate
();
}
}
/**
* Called when the state of a download changes. The default implementation is a no-op.
*
* @param download The new state of the download.
...
...
@@ -543,7 +555,7 @@ public abstract class DownloadService extends Service {
||
download
.
state
==
Download
.
STATE_RESTARTING
)
{
foregroundNotificationUpdater
.
startPeriodicUpdates
();
}
else
{
foregroundNotificationUpdater
.
up
date
();
foregroundNotificationUpdater
.
invali
date
();
}
}
}
...
...
@@ -551,7 +563,7 @@ public abstract class DownloadService extends Service {
private
void
notifyDownloadRemoved
(
Download
download
)
{
onDownloadRemoved
(
download
);
if
(
foregroundNotificationUpdater
!=
null
)
{
foregroundNotificationUpdater
.
up
date
();
foregroundNotificationUpdater
.
invali
date
();
}
}
...
...
@@ -583,11 +595,12 @@ public abstract class DownloadService extends Service {
return
new
Intent
(
context
,
clazz
).
setAction
(
action
);
}
private
final
class
ForegroundNotificationUpdater
implements
Runnable
{
private
final
class
ForegroundNotificationUpdater
{
private
final
int
notificationId
;
private
final
long
updateInterval
;
private
final
Handler
handler
;
private
final
Runnable
callback
;
private
boolean
periodicUpdatesStarted
;
private
boolean
notificationDisplayed
;
...
...
@@ -596,6 +609,7 @@ public abstract class DownloadService extends Service {
this
.
notificationId
=
notificationId
;
this
.
updateInterval
=
updateInterval
;
this
.
handler
=
new
Handler
(
Looper
.
getMainLooper
());
this
.
callback
=
this
::
update
;
}
public
void
startPeriodicUpdates
()
{
...
...
@@ -605,28 +619,29 @@ public abstract class DownloadService extends Service {
public
void
stopPeriodicUpdates
()
{
periodicUpdatesStarted
=
false
;
handler
.
removeCallbacks
(
this
);
handler
.
removeCallbacks
(
callback
);
}
public
void
update
()
{
Download
[]
downloads
=
downloadManager
.
getCurrentDownloads
();
startForeground
(
notificationId
,
getForegroundNotification
(
downloads
));
notificationDisplayed
=
true
;
if
(
periodicUpdatesStarted
)
{
handler
.
removeCallbacks
(
this
);
handler
.
postDelayed
(
this
,
updateInterval
);
public
void
showNotificationIfNotAlready
()
{
if
(!
notificationDisplayed
)
{
update
();
}
}
public
void
showNotificationIfNotAlready
()
{
if
(
!
notificationDisplayed
)
{
public
void
invalidate
()
{
if
(
notificationDisplayed
)
{
update
();
}
}
@Override
public
void
run
()
{
update
();
private
void
update
()
{
Download
[]
downloads
=
downloadManager
.
getCurrentDownloads
();
startForeground
(
notificationId
,
getForegroundNotification
(
downloads
));
notificationDisplayed
=
true
;
if
(
periodicUpdatesStarted
)
{
handler
.
removeCallbacks
(
callback
);
handler
.
postDelayed
(
callback
,
updateInterval
);
}
}
}
...
...
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