From 471b3b7db187d54d67127c5a2344ca0c889cf16f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Tue, 25 Nov 2025 21:40:08 +0000 Subject: [PATCH] Avoid Microsoft Teams notification burst during calls (#5525) --- .../externalevents/NotificationListener.java | 18 +++++++++++++++++- .../externalevents/PhoneCallReceiver.java | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) 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 3c9633cd12..4ccbd487be 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java @@ -703,7 +703,7 @@ public class NotificationListener extends NotificationListenerService { boolean callStarted = false; if (noti.actions != null && noti.actions.length > 0) { for (Notification.Action action : noti.actions) { - LOG.info("Found call action: " + action.title); + LOG.info("Found call action: {}", action.title); } if (noti.actions.length == 1) { if (mLastCallCommand == CallSpec.CALL_INCOMING) { @@ -723,6 +723,22 @@ public class NotificationListener extends NotificationListenerService { }*/ } + if (app.equals("com.microsoft.teams")) { + // #5525 - microsoft teams spams notifications with slightly increasing timestamps + // we use a different key for the burst prevention to prevent suppressing notifications + final String burstPreventionKey = "call:" + app; + final Long notificationBurstPreventionValue = notificationBurstPrevention.get(burstPreventionKey); + long curTime = System.nanoTime(); + if (notificationBurstPreventionValue != null) { + long diff = curTime - notificationBurstPreventionValue; + if (diff < TimeUnit.SECONDS.toNanos(1)) { + LOG.info("Ignoring burst call notification from microsoft teams, last one was {} ms ago", TimeUnit.NANOSECONDS.toMillis(diff)); + return; + } + } + notificationBurstPrevention.put(burstPreventionKey, curTime); + } + // figure out sender String number = null; String notiTitle = null; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PhoneCallReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PhoneCallReceiver.java index 64a0011ce6..cab966e3f1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PhoneCallReceiver.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PhoneCallReceiver.java @@ -49,6 +49,8 @@ public class PhoneCallReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { + LOG.debug("Got phone call intent: {}", intent.getAction()); + TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE); if ("android.intent.action.NEW_OUTGOING_CALL".equals(intent.getAction())) { mSavedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");