Merge pull request #3199 from jas14/fix-3197

Fix scheduling tasks on shutdown executor
This commit is contained in:
H. Lehmann 2019-05-22 08:09:45 +02:00 committed by GitHub
commit 0f79fc4d9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -228,6 +228,15 @@ public class PlaybackServiceTaskManagerTest {
pstm.shutdown();
}
@Test
public void testStartWidgetUpdaterAfterShutdown() {
// Should not throw.
final Context c = InstrumentationRegistry.getInstrumentation().getTargetContext();
PlaybackServiceTaskManager pstm = new PlaybackServiceTaskManager(c, defaultPSTM);
pstm.shutdown();
pstm.startWidgetUpdater();
}
@Test
public void testIsWidgetUpdaterActive() {
final Context c = InstrumentationRegistry.getInstrumentation().getTargetContext();

View File

@ -165,7 +165,7 @@ public class PlaybackServiceTaskManager {
* Starts the widget updater task. If the widget updater is already active, nothing will happen.
*/
public synchronized void startWidgetUpdater() {
if (!isWidgetUpdaterActive()) {
if (!isWidgetUpdaterActive() && !schedExecutor.isShutdown()) {
Runnable widgetUpdater = callback::onWidgetUpdaterTick;
widgetUpdater = useMainThreadIfNecessary(widgetUpdater);
widgetUpdaterFuture = schedExecutor.scheduleWithFixedDelay(widgetUpdater, WIDGET_UPDATER_NOTIFICATION_INTERVAL,