From eca8fc90b8a0a4cb6d83baa1277df8b391e634bb Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Fri, 3 Jun 2016 12:56:30 +0200 Subject: [PATCH] Prevent onServiceConnected ClassCastException --- .../antennapod/service/PlayerWidgetService.java | 7 ++++--- .../core/util/playback/PlaybackController.java | 17 +++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/service/PlayerWidgetService.java b/app/src/main/java/de/danoeh/antennapod/service/PlayerWidgetService.java index 323060f81..6d1429df1 100644 --- a/app/src/main/java/de/danoeh/antennapod/service/PlayerWidgetService.java +++ b/app/src/main/java/de/danoeh/antennapod/service/PlayerWidgetService.java @@ -196,9 +196,10 @@ public class PlayerWidgetService extends Service { public void onServiceConnected(ComponentName className, IBinder service) { Log.d(TAG, "Connection to service established"); synchronized (psLock) { - playbackService = ((PlaybackService.LocalBinder) service) - .getService(); - startViewUpdaterIfNotRunning(); + if(service instanceof PlaybackService.LocalBinder == false) { + playbackService = ((PlaybackService.LocalBinder) service).getService(); + startViewUpdaterIfNotRunning(); + } } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java index 7870c747e..041831e80 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java @@ -258,14 +258,15 @@ public abstract class PlaybackController { private final ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { - playbackService = ((PlaybackService.LocalBinder) service) - .getService(); - if (!released) { - queryService(); - Log.d(TAG, "Connection to Service established"); - } else { - Log.i(TAG, "Connection to playback service has been established, " + - "but controller has already been released"); + if(service instanceof PlaybackService.LocalBinder) { + playbackService = ((PlaybackService.LocalBinder) service).getService(); + if (!released) { + queryService(); + Log.d(TAG, "Connection to Service established"); + } else { + Log.i(TAG, "Connection to playback service has been established, " + + "but controller has already been released"); + } } }