Avoid Microsoft Teams notification burst during calls (#5525)

This commit is contained in:
José Rebelo
2025-11-25 21:40:08 +00:00
parent 4d46d6058e
commit 471b3b7db1
2 changed files with 19 additions and 1 deletions
@@ -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;
@@ -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");