diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/EventHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/EventHandler.java index cfeb80afd..4ce49b153 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/EventHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/EventHandler.java @@ -2,7 +2,6 @@ package nodomain.freeyourgadget.gadgetbridge; import android.net.Uri; -import java.net.URI; import java.util.UUID; public interface EventHandler { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBDevice.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBDevice.java index 308fb803a..2058b61f4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBDevice.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBDevice.java @@ -131,9 +131,10 @@ public class GBDevice implements Parcelable { /** * Marks the device as busy, performing a certain task. While busy, no other operations will * be performed on the device. - * + *
* Note that nested busy tasks are not supported, every single call to #setBusyTask() * or unsetBusy() has an effect. + * * @param task a textual name of the task to be performed, possibly displayed to the user */ public void setBusyTask(String task) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/GattCallback.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/GattCallback.java index 6bc005737..5a232fa28 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/GattCallback.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/GattCallback.java @@ -68,19 +68,19 @@ public interface GattCallback { BluetoothGattCharacteristic characteristic); /** - * @see BluetoothGattCallback#onDescriptorRead(BluetoothGatt, BluetoothGattDescriptor, int) * @param gatt * @param descriptor * @param status + * @see BluetoothGattCallback#onDescriptorRead(BluetoothGatt, BluetoothGattDescriptor, int) */ public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status); /** - * @see BluetoothGattCallback#onDescriptorWrite(BluetoothGatt, BluetoothGattDescriptor, int) * @param gatt * @param descriptor * @param status + * @see BluetoothGattCallback#onDescriptorWrite(BluetoothGatt, BluetoothGattDescriptor, int) */ public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/NotifyAction.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/NotifyAction.java index 37d87b7d2..47ec24f7c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/NotifyAction.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/NotifyAction.java @@ -3,13 +3,10 @@ package nodomain.freeyourgadget.gadgetbridge.btle; import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGattCallback; import android.bluetooth.BluetoothGattCharacteristic; -import android.bluetooth.BluetoothGattDescriptor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import nodomain.freeyourgadget.gadgetbridge.miband.MiBandService; - /** * Enables or disables notifications for a given GATT characteristic. * The result will be made available asynchronously through the diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/PlainAction.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/PlainAction.java index d5455fed4..fad4f0092 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/PlainAction.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/PlainAction.java @@ -1,7 +1,5 @@ package nodomain.freeyourgadget.gadgetbridge.btle; -import android.bluetooth.BluetoothGatt; - /** * An abstract non-BTLE action. It performs no bluetooth operation, * does not have a BluetoothGattCharacteristic instance and expects no result. diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/SetDeviceBusyAction.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/SetDeviceBusyAction.java index 05f680134..27f66c6f7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/SetDeviceBusyAction.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/SetDeviceBusyAction.java @@ -12,7 +12,8 @@ public class SetDeviceBusyAction extends PlainAction { /** * When run, will mark the device as busy (or not busy). - * @param device the device to mark + * + * @param device the device to mark * @param busyTask the task name to set as busy task, or null to mark as not busy * @param context */ diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/TransactionBuilder.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/TransactionBuilder.java index 5db0e68ca..775caa59d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/TransactionBuilder.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/TransactionBuilder.java @@ -5,8 +5,6 @@ import android.bluetooth.BluetoothGattCharacteristic; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import nodomain.freeyourgadget.gadgetbridge.miband.MiBandNotifyAction; - public class TransactionBuilder { private static final Logger LOG = LoggerFactory.getLogger(TransactionBuilder.class); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/ActivityDatabaseHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/ActivityDatabaseHandler.java index 319a25716..c41052d2b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/ActivityDatabaseHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/ActivityDatabaseHandler.java @@ -44,6 +44,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper { /** * WITHOUT ROWID is only available with sqlite 3.8.2, which is available * with Lollipop and later. + * * @return the "WITHOUT ROWID" string or an empty string for pre-Lollipop devices */ private String getWithoutRowId() { @@ -55,7 +56,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper { @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - if (newVersion == 5 && (oldVersion == 4 || oldVersion ==3)) { + if (newVersion == 5 && (oldVersion == 4 || oldVersion == 3)) { String CREATE_NEW_GBACTIVITYSAMPLES_TABLE = "CREATE TABLE NEW (" + KEY_TIMESTAMP + " INT," + KEY_PROVIDER + " TINYINT," @@ -64,8 +65,8 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper { + KEY_TYPE + " TINYINT," + " PRIMARY KEY (" + KEY_TIMESTAMP + "," + KEY_PROVIDER + ") ON CONFLICT REPLACE)" + getWithoutRowId(); db.execSQL(CREATE_NEW_GBACTIVITYSAMPLES_TABLE); - db.execSQL("insert into NEW select timestamp,provider,intensity,steps,type from "+ TABLE_GBACTIVITYSAMPLES+";"); - db.execSQL("Drop table "+TABLE_GBACTIVITYSAMPLES+";"); + db.execSQL("insert into NEW select timestamp,provider,intensity,steps,type from " + TABLE_GBACTIVITYSAMPLES + ";"); + db.execSQL("Drop table " + TABLE_GBACTIVITYSAMPLES + ";"); db.execSQL("alter table NEW RENAME TO " + TABLE_GBACTIVITYSAMPLES + ";"); } else { //FIXME: do not just recreate diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandNotifyAction.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandNotifyAction.java index 585c6a171..936fb26b6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandNotifyAction.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandNotifyAction.java @@ -8,16 +8,14 @@ import android.bluetooth.BluetoothGattDescriptor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import nodomain.freeyourgadget.gadgetbridge.btle.BtLEAction; import nodomain.freeyourgadget.gadgetbridge.btle.NotifyAction; import nodomain.freeyourgadget.gadgetbridge.btle.TransactionBuilder; -import nodomain.freeyourgadget.gadgetbridge.miband.MiBandService; /** * Enables or disables notifications for a given GATT characteristic. * The result will be made available asynchronously through the * {@link BluetoothGattCallback}. - * + * * This class is Mi Band specific. */ public class MiBandNotifyAction extends NotifyAction { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandService.java index a181c6920..ff53ae32a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandService.java @@ -128,7 +128,7 @@ public class MiBandService { public static final byte COMMAND_REBOOT = 0xc; public static final byte COMMAND_SEND_NOTIFICATION = 0x8; - + public static final byte COMMAND_STOP_MOTOR_VIBRATE = 0x13; public static final byte COMMAND_CONFIRM_ACTIVITY_DATA_TRANSFER_COMPLETE = 0xa; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandSupport.java index 498a3a627..979caa045 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandSupport.java @@ -86,6 +86,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { * Last action of initialization sequence. Sets the device to initialized. * It is only invoked if all other actions were successfully run, so the device * must be initialized, then. + * * @param builder */ private void setInitialized(TransactionBuilder builder) { @@ -150,10 +151,10 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { builder.queue(getQueue()); } - private static final byte[] startVibrate = new byte[] { MiBandService.COMMAND_SEND_NOTIFICATION, 1 }; - private static final byte[] stopVibrate = new byte[] { MiBandService.COMMAND_STOP_MOTOR_VIBRATE }; - private static final byte[] reboot = new byte[]{ MiBandService.COMMAND_REBOOT }; - private static final byte[] fetch = new byte[]{ MiBandService.COMMAND_FETCH_DATA }; + private static final byte[] startVibrate = new byte[]{MiBandService.COMMAND_SEND_NOTIFICATION, 1}; + private static final byte[] stopVibrate = new byte[]{MiBandService.COMMAND_STOP_MOTOR_VIBRATE}; + private static final byte[] reboot = new byte[]{MiBandService.COMMAND_REBOOT}; + private static final byte[] fetch = new byte[]{MiBandService.COMMAND_FETCH_DATA}; private byte[] getNotification(long vibrateDuration, int vibrateTimes, int flashTimes, int flashColour, int originalColour, long flashDuration) { byte[] vibrate = new byte[]{MiBandService.COMMAND_SEND_NOTIFICATION, (byte) 1}; @@ -452,11 +453,11 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { } private void handleActivityNotif(byte[] value) { - if (value.length == 11 ) { + if (value.length == 11) { // byte 0 is the data type: 1 means that each minute is represented by a triplet of bytes int dataType = value[0]; // byte 1 to 6 represent a timestamp - GregorianCalendar timestamp = new GregorianCalendar(value[1]+2000, + GregorianCalendar timestamp = new GregorianCalendar(value[1] + 2000, value[2], value[3], value[4], @@ -470,15 +471,15 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { // counter of this data block int dataUntilNextHeader = (value[9] & 0xff) | ((value[10] & 0xff) << 8); - dataUntilNextHeader *= (dataType ==1) ? 3 : 1; + dataUntilNextHeader *= (dataType == 1) ? 3 : 1; // there is a total of totalDataToRead that will come in chunks (3 bytes per minute if dataType == 1), // these chunks are usually 20 bytes long and grouped in blocks // after dataUntilNextHeader bytes we will get a new packet of 11 bytes that should be parsed // as we just did - LOG.info("total data to read: "+ totalDataToRead +" len: " + (totalDataToRead / 3) + " minute(s)"); - LOG.info("data to read until next header: "+ dataUntilNextHeader +" len: " + (dataUntilNextHeader / 3) + " minute(s)"); + LOG.info("total data to read: " + totalDataToRead + " len: " + (totalDataToRead / 3) + " minute(s)"); + LOG.info("data to read until next header: " + dataUntilNextHeader + " len: " + (dataUntilNextHeader / 3) + " minute(s)"); LOG.info("TIMESTAMP: " + DateFormat.getDateTimeInstance().format(timestamp.getTime()).toString() + " magic byte: " + dataUntilNextHeader); this.activityDataRemainingBytes = this.activityDataUntilNextHeader = dataUntilNextHeader; @@ -499,7 +500,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { //I don't like this clause, but until we figure out why we get different data sometimes this should work if (value.length == 20 || value.length == this.activityDataRemainingBytes) { System.arraycopy(value, 0, this.activityDataHolder, this.activityDataHolderProgress, value.length); - this.activityDataHolderProgress +=value.length; + this.activityDataHolderProgress += value.length; this.activityDataRemainingBytes -= value.length; if (this.activityDataHolderSize == this.activityDataHolderProgress) { @@ -508,7 +509,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { } else { // the length of the chunk is not what we expect. We need to make sense of this data LOG.warn("GOT UNEXPECTED ACTIVITY DATA WITH LENGTH: " + value.length + ", EXPECTED LENGTH: " + this.activityDataRemainingBytes); - for (byte b: value){ + for (byte b : value) { LOG.warn("DATA: " + String.format("0x%8x", b)); } } @@ -521,10 +522,10 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { ActivityDatabaseHandler dbHandler = GBApplication.getActivityDatabaseHandler(); try (SQLiteDatabase db = dbHandler.getWritableDatabase()) { // explicitly keep the db open while looping over the samples - for (int i=0; i