diff options
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/tor/TorNotificationManager.java | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/tor/TorNotificationManager.java b/app/src/main/java/se/leap/bitmaskclient/tor/TorNotificationManager.java index 507de4ae..3f3fbf4f 100644 --- a/app/src/main/java/se/leap/bitmaskclient/tor/TorNotificationManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/tor/TorNotificationManager.java @@ -30,6 +30,9 @@ import se.leap.bitmaskclient.R; public class TorNotificationManager { public final static int TOR_SERVICE_NOTIFICATION_ID = 10; static final String NOTIFICATION_CHANNEL_NEWSTATUS_ID = "bitmask_tor_service_news"; + private long lastNotificationTime = 0; + // debounce timeout in milliseconds + private final static long NOTIFICATION_DEBOUNCE_TIME = 500; public TorNotificationManager() {} @@ -48,6 +51,9 @@ public class TorNotificationManager { } public void buildTorNotification(Context context, String state, String message, int progress) { + if (shouldDropNotification()) { + return; + } NotificationManager notificationManager = initNotificationManager(context); if (notificationManager == null) { return; @@ -69,6 +75,15 @@ public class TorNotificationManager { notificationManager.notify(TOR_SERVICE_NOTIFICATION_ID, notificationBuilder.build()); } + private boolean shouldDropNotification() { + long now = System.currentTimeMillis(); + if (now - lastNotificationTime < NOTIFICATION_DEBOUNCE_TIME) { + return true; + } + lastNotificationTime = now; + return false; + } + private static NotificationManager initNotificationManager(Context context) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); |