From b4bbf6186c2afefdcba07463c78e00ffe44f4523 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Thu, 10 Jan 2019 17:30:49 +0100 Subject: [PATCH] Catch SecurityException when Notfication access was not granted when getting media session Fixes #1387 --- .../receivers/GBMusicControlReceiver.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/receivers/GBMusicControlReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/receivers/GBMusicControlReceiver.java index a0f95ebe2..dbeecd0e7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/receivers/GBMusicControlReceiver.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/receivers/GBMusicControlReceiver.java @@ -106,14 +106,17 @@ public class GBMusicControlReceiver extends BroadcastReceiver { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { MediaSessionManager mediaSessionManager = (MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE); - - List controllers = mediaSessionManager.getActiveSessions( - new ComponentName(context, NotificationListener.class)); try { - MediaController controller = controllers.get(0); - audioPlayer = controller.getPackageName(); - } catch (IndexOutOfBoundsException e) { - LOG.error("No media controller available", e); + List controllers = mediaSessionManager.getActiveSessions( + new ComponentName(context, NotificationListener.class)); + try { + MediaController controller = controllers.get(0); + audioPlayer = controller.getPackageName(); + } catch (IndexOutOfBoundsException e) { + LOG.error("No media controller available", e); + } + } catch (SecurityException e) { + LOG.warn("No permission to get media sessions - did not grant notification access?", e); } } return audioPlayer;