From b321956c7c76510a67ca3f04d90cdf2462c560db Mon Sep 17 00:00:00 2001 From: Dmitry Markin Date: Wed, 29 Jan 2020 23:58:16 +0300 Subject: [PATCH] Stop an incoming VoIP call notification when the call is answered --- .../externalevents/NotificationListener.java | 16 +++++++++++++--- .../gadgetbridge/model/CallSpec.java | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java index f01e51d52..a2de250a2 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java @@ -116,6 +116,7 @@ public class NotificationListener extends NotificationListenerService { public static ArrayList notificationStack = new ArrayList<>(); private long activeCallPostTime; + private int mLastCallCommand = CallSpec.CALL_UNDEFINED; private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @@ -452,13 +453,20 @@ public class NotificationListener extends NotificationListenerService { } Notification noti = sbn.getNotification(); dumpExtras(noti.extras); + boolean callStarted = false; if(noti.actions != null && noti.actions.length > 0) { for (Notification.Action action : noti.actions) { LOG.info("Found call action: " + action.title); } if (noti.actions.length == 1) { - LOG.info("There is only one call action, assuming outgoing call and ignoring"); - return; + if (mLastCallCommand == CallSpec.CALL_INCOMING) { + LOG.info("There is only one call action and previous state was CALL_INCOMING, assuming call started"); + callStarted = true; + } else { + LOG.info("There is only one call action and previous state was not CALL_INCOMING, assuming outgoing call / duplicate notification and ignoring"); + // FIXME: is there a way to detect transition CALL_OUTGOING -> CALL_START for more complete VoIP call state tracking? + return; + } } /*try { LOG.info("Executing first action"); @@ -481,7 +489,8 @@ public class NotificationListener extends NotificationListenerService { activeCallPostTime = sbn.getPostTime(); CallSpec callSpec = new CallSpec(); callSpec.number = number; - callSpec.command = CallSpec.CALL_INCOMING; + callSpec.command = callStarted ? CallSpec.CALL_START : CallSpec.CALL_INCOMING; + mLastCallCommand = callSpec.command; GBApplication.deviceService().onSetCallState(callSpec); } @@ -653,6 +662,7 @@ public class NotificationListener extends NotificationListenerService { activeCallPostTime = 0; CallSpec callSpec = new CallSpec(); callSpec.command = CallSpec.CALL_END; + mLastCallCommand = callSpec.command; GBApplication.deviceService().onSetCallState(callSpec); } // FIXME: DISABLED for now diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/CallSpec.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/CallSpec.java index 2e547f244..817ba872c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/CallSpec.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/CallSpec.java @@ -17,7 +17,7 @@ package nodomain.freeyourgadget.gadgetbridge.model; public class CallSpec { - public static final int CALL_UNDEFINED = 1; + public static final int CALL_UNDEFINED = 0; public static final int CALL_ACCEPT = 1; public static final int CALL_INCOMING = 2; public static final int CALL_OUTGOING = 3;