From 839da4f06acc9dc1aa575bdb760b5200c87d3b94 Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Thu, 20 Oct 2016 21:42:36 +0200 Subject: [PATCH] Shuffle some logging things around --- .../freeyourgadget/gadgetbridge/Logging.java | 8 +++++ .../btle/AbstractBTLEDeviceSupport.java | 34 ++++++++++++++----- .../devices/miband/MiBand2Support.java | 15 +------- .../service/devices/miband/MiBandSupport.java | 16 ++------- .../vibratissimo/VibratissimoSupport.java | 1 + 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/Logging.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/Logging.java index 7ea3c8e90..75504d790 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/Logging.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/Logging.java @@ -125,4 +125,12 @@ public abstract class Logging { } return false; } + + public static void logBytes(Logger logger, byte[] value) { + if (value != null) { + for (byte b : value) { + logger.warn("DATA: " + String.format("0x%2x", b)); + } + } + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/AbstractBTLEDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/AbstractBTLEDeviceSupport.java index c65262c2d..e87c50e32 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/AbstractBTLEDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/AbstractBTLEDeviceSupport.java @@ -6,7 +6,6 @@ import android.bluetooth.BluetoothGattDescriptor; import android.bluetooth.BluetoothGattService; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.ArrayList; @@ -16,6 +15,7 @@ import java.util.List; import java.util.Set; import java.util.UUID; +import nodomain.freeyourgadget.gadgetbridge.Logging; import nodomain.freeyourgadget.gadgetbridge.service.AbstractDeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.CheckInitializedAction; import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.AbstractBleProfile; @@ -32,15 +32,21 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.AbstractBlePro * @see BtLEQueue */ public abstract class AbstractBTLEDeviceSupport extends AbstractDeviceSupport implements GattCallback { - private static final Logger LOG = LoggerFactory.getLogger(AbstractBTLEDeviceSupport.class); - private BtLEQueue mQueue; private HashMap mAvailableCharacteristics; private final Set mSupportedServices = new HashSet<>(4); - private final List> mSupportedProfiles = new ArrayList<>(); + private Logger logger; + private final List> mSupportedProfiles = new ArrayList<>(); public static final String BASE_UUID = "0000%s-0000-1000-8000-00805f9b34fb"; //this is common for all BTLE devices. see http://stackoverflow.com/questions/18699251/finding-out-android-bluetooth-le-gatt-profiles + public AbstractBTLEDeviceSupport(Logger logger) { + this.logger = logger; + if (logger == null) { + throw new IllegalArgumentException("logger must not be null"); + } + } + @Override public boolean connect() { if (mQueue == null) { @@ -168,27 +174,27 @@ public abstract class AbstractBTLEDeviceSupport extends AbstractDeviceSupport im private void gattServicesDiscovered(List discoveredGattServices) { if (discoveredGattServices == null) { - LOG.warn("No gatt services discovered: null!"); + logger.warn("No gatt services discovered: null!"); return; } Set supportedServices = getSupportedServices(); mAvailableCharacteristics = new HashMap<>(); for (BluetoothGattService service : discoveredGattServices) { if (supportedServices.contains(service.getUuid())) { - LOG.debug("discovered supported service: " + BleNamesResolver.resolveServiceName(service.getUuid().toString()) + ": " + service.getUuid()); + logger.debug("discovered supported service: " + BleNamesResolver.resolveServiceName(service.getUuid().toString()) + ": " + service.getUuid()); List characteristics = service.getCharacteristics(); if (characteristics == null || characteristics.isEmpty()) { - LOG.warn("Supported LE service " + service.getUuid() + "did not return any characteristics"); + logger.warn("Supported LE service " + service.getUuid() + "did not return any characteristics"); continue; } HashMap intmAvailableCharacteristics = new HashMap<>(characteristics.size()); for (BluetoothGattCharacteristic characteristic : characteristics) { intmAvailableCharacteristics.put(characteristic.getUuid(), characteristic); - LOG.info(" characteristic: " + BleNamesResolver.resolveCharacteristicName(characteristic.getUuid().toString()) + ": " + characteristic.getUuid()); + logger.info(" characteristic: " + BleNamesResolver.resolveCharacteristicName(characteristic.getUuid().toString()) + ": " + characteristic.getUuid()); } mAvailableCharacteristics.putAll(intmAvailableCharacteristics); } else { - LOG.debug("discovered unsupported service: " + BleNamesResolver.resolveServiceName(service.getUuid().toString()) + ": " + service.getUuid()); + logger.debug("discovered unsupported service: " + BleNamesResolver.resolveServiceName(service.getUuid().toString()) + ": " + service.getUuid()); } } } @@ -197,6 +203,16 @@ public abstract class AbstractBTLEDeviceSupport extends AbstractDeviceSupport im return mSupportedServices; } + /** + * Utility method that may be used to log incoming messages when we don't know how to deal with them yet. + * + * @param value + */ + public void logMessageContent(byte[] value) { + logger.info("RECEIVED DATA WITH LENGTH: " + ((value != null) ? value.length : "(null)")); + Logging.logBytes(logger, value); + } + // default implementations of event handler methods (gatt callbacks) @Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBand2Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBand2Support.java index d9bdb5b56..507059762 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBand2Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBand2Support.java @@ -106,6 +106,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport { private final GBDeviceEventBatteryInfo batteryCmd = new GBDeviceEventBatteryInfo(); public MiBand2Support() { + super(LOG); addSupportedService(GattService.UUID_SERVICE_GENERIC_ACCESS); addSupportedService(GattService.UUID_SERVICE_GENERIC_ATTRIBUTE); addSupportedService(GattService.UUID_SERVICE_HEART_RATE); @@ -917,20 +918,6 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport { return false; } - /** - * Utility method that may be used to log incoming messages when we don't know how to deal with them yet. - * - * @param value - */ - public void logMessageContent(byte[] value) { - LOG.info("RECEIVED DATA WITH LENGTH: " + ((value != null) ? value.length : "(null)")); - if (value != null) { - for (byte b : value) { - LOG.warn("DATA: " + String.format("0x%2x", b)); - } - } - } - public void logDate(byte[] value, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { GregorianCalendar calendar = MiBandDateConverter.rawBytesToCalendar(value); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java index c3dc5bee4..7ae98b72e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.GBApplication; +import nodomain.freeyourgadget.gadgetbridge.Logging; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; @@ -103,6 +104,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { private RealtimeSamplesSupport realtimeSamplesSupport; public MiBandSupport() { + super(LOG); addSupportedService(GattService.UUID_SERVICE_GENERIC_ACCESS); addSupportedService(GattService.UUID_SERVICE_GENERIC_ATTRIBUTE); addSupportedService(MiBandService.UUID_SERVICE_MIBAND_SERVICE); @@ -873,20 +875,6 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { return false; } - /** - * Utility method that may be used to log incoming messages when we don't know how to deal with them yet. - * - * @param value - */ - public void logMessageContent(byte[] value) { - LOG.info("RECEIVED DATA WITH LENGTH: " + ((value != null) ? value.length : "(null)")); - if (value != null) { - for (byte b : value) { - LOG.warn("DATA: " + String.format("0x%2x", b)); - } - } - } - public void logDate(byte[] value, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { GregorianCalendar calendar = MiBandDateConverter.rawBytesToCalendar(value); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vibratissimo/VibratissimoSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vibratissimo/VibratissimoSupport.java index cacd86587..e53d63b8b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vibratissimo/VibratissimoSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vibratissimo/VibratissimoSupport.java @@ -53,6 +53,7 @@ public class VibratissimoSupport extends AbstractBTLEDeviceSupport { }; public VibratissimoSupport() { + super(LOG); addSupportedService(GattService.UUID_SERVICE_GENERIC_ACCESS); addSupportedService(GattService.UUID_SERVICE_GENERIC_ATTRIBUTE); addSupportedService(GattService.UUID_SERVICE_DEVICE_INFORMATION);