Some cleanup + actually remember event time and kind for throttling

This commit is contained in:
cpfeiffer 2015-06-06 23:59:53 +02:00
parent f5a569610f
commit ab97b544f0
4 changed files with 5 additions and 8 deletions

View File

@ -25,7 +25,6 @@ import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBDevice.State;
import nodomain.freeyourgadget.gadgetbridge.miband.MiBandSupport;
import nodomain.freeyourgadget.gadgetbridge.pebble.PebbleIoThread;
import nodomain.freeyourgadget.gadgetbridge.pebble.PebbleSupport;
public class BluetoothCommunicationService extends Service {

View File

@ -18,7 +18,7 @@ public class ServiceDeviceSupport implements DeviceSupport {
private final DeviceSupport delegate;
private long lastNoficationTime = 0;
private String lastNotificationType;
private String lastNotificationKind;
public ServiceDeviceSupport(DeviceSupport delegate) {
this.delegate = delegate;
@ -79,11 +79,13 @@ public class ServiceDeviceSupport implements DeviceSupport {
private boolean checkThrottle(String notificationKind) {
long currentTime = System.currentTimeMillis();
if ((currentTime - lastNoficationTime) < THROTTLING_THRESHOLD) {
if (notificationKind != null && notificationKind.equals(lastNotificationType)) {
if (notificationKind != null && notificationKind.equals(lastNotificationKind)) {
LOG.info("Ignoring " + notificationKind + " because of throttling threshold reached");
return true;
}
}
lastNoficationTime = currentTime;
lastNotificationKind = notificationKind;
return false;
}

View File

@ -10,14 +10,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.URI;
import java.text.DateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.UUID;
import java.text.DateFormat;
import nodomain.freeyourgadget.gadgetbridge.GBActivitySample;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.GBCommand;

View File

@ -2,8 +2,6 @@ package nodomain.freeyourgadget.gadgetbridge.pebble;
import android.net.Uri;
import java.net.URI;
import nodomain.freeyourgadget.gadgetbridge.AbstractBTDeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.GBDeviceIoThread;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceProtocol;