mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-09-01 20:15:52 +02:00
Reformat code and optimize imports
This commit is contained in:
parent
ad4f708140
commit
56d314d054
@ -2,7 +2,6 @@ package nodomain.freeyourgadget.gadgetbridge;
|
|||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface EventHandler {
|
public interface EventHandler {
|
||||||
|
@ -131,9 +131,10 @@ public class GBDevice implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Marks the device as busy, performing a certain task. While busy, no other operations will
|
* Marks the device as busy, performing a certain task. While busy, no other operations will
|
||||||
* be performed on the device.
|
* be performed on the device.
|
||||||
*
|
* <p/>
|
||||||
* Note that nested busy tasks are not supported, every single call to #setBusyTask()
|
* Note that nested busy tasks are not supported, every single call to #setBusyTask()
|
||||||
* or unsetBusy() has an effect.
|
* or unsetBusy() has an effect.
|
||||||
|
*
|
||||||
* @param task a textual name of the task to be performed, possibly displayed to the user
|
* @param task a textual name of the task to be performed, possibly displayed to the user
|
||||||
*/
|
*/
|
||||||
public void setBusyTask(String task) {
|
public void setBusyTask(String task) {
|
||||||
|
@ -68,19 +68,19 @@ public interface GattCallback {
|
|||||||
BluetoothGattCharacteristic characteristic);
|
BluetoothGattCharacteristic characteristic);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see BluetoothGattCallback#onDescriptorRead(BluetoothGatt, BluetoothGattDescriptor, int)
|
|
||||||
* @param gatt
|
* @param gatt
|
||||||
* @param descriptor
|
* @param descriptor
|
||||||
* @param status
|
* @param status
|
||||||
|
* @see BluetoothGattCallback#onDescriptorRead(BluetoothGatt, BluetoothGattDescriptor, int)
|
||||||
*/
|
*/
|
||||||
public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
|
public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
|
||||||
int status);
|
int status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see BluetoothGattCallback#onDescriptorWrite(BluetoothGatt, BluetoothGattDescriptor, int)
|
|
||||||
* @param gatt
|
* @param gatt
|
||||||
* @param descriptor
|
* @param descriptor
|
||||||
* @param status
|
* @param status
|
||||||
|
* @see BluetoothGattCallback#onDescriptorWrite(BluetoothGatt, BluetoothGattDescriptor, int)
|
||||||
*/
|
*/
|
||||||
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
|
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
|
||||||
int status);
|
int status);
|
||||||
|
@ -3,13 +3,10 @@ package nodomain.freeyourgadget.gadgetbridge.btle;
|
|||||||
import android.bluetooth.BluetoothGatt;
|
import android.bluetooth.BluetoothGatt;
|
||||||
import android.bluetooth.BluetoothGattCallback;
|
import android.bluetooth.BluetoothGattCallback;
|
||||||
import android.bluetooth.BluetoothGattCharacteristic;
|
import android.bluetooth.BluetoothGattCharacteristic;
|
||||||
import android.bluetooth.BluetoothGattDescriptor;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.miband.MiBandService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables or disables notifications for a given GATT characteristic.
|
* Enables or disables notifications for a given GATT characteristic.
|
||||||
* The result will be made available asynchronously through the
|
* The result will be made available asynchronously through the
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.btle;
|
package nodomain.freeyourgadget.gadgetbridge.btle;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothGatt;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An abstract non-BTLE action. It performs no bluetooth operation,
|
* An abstract non-BTLE action. It performs no bluetooth operation,
|
||||||
* does not have a BluetoothGattCharacteristic instance and expects no result.
|
* does not have a BluetoothGattCharacteristic instance and expects no result.
|
||||||
|
@ -12,7 +12,8 @@ public class SetDeviceBusyAction extends PlainAction {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* When run, will mark the device as busy (or not busy).
|
* 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 busyTask the task name to set as busy task, or null to mark as not busy
|
||||||
* @param context
|
* @param context
|
||||||
*/
|
*/
|
||||||
|
@ -5,8 +5,6 @@ import android.bluetooth.BluetoothGattCharacteristic;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.miband.MiBandNotifyAction;
|
|
||||||
|
|
||||||
public class TransactionBuilder {
|
public class TransactionBuilder {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(TransactionBuilder.class);
|
private static final Logger LOG = LoggerFactory.getLogger(TransactionBuilder.class);
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper {
|
|||||||
/**
|
/**
|
||||||
* WITHOUT ROWID is only available with sqlite 3.8.2, which is available
|
* WITHOUT ROWID is only available with sqlite 3.8.2, which is available
|
||||||
* with Lollipop and later.
|
* with Lollipop and later.
|
||||||
|
*
|
||||||
* @return the "WITHOUT ROWID" string or an empty string for pre-Lollipop devices
|
* @return the "WITHOUT ROWID" string or an empty string for pre-Lollipop devices
|
||||||
*/
|
*/
|
||||||
private String getWithoutRowId() {
|
private String getWithoutRowId() {
|
||||||
@ -55,7 +56,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
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 ("
|
String CREATE_NEW_GBACTIVITYSAMPLES_TABLE = "CREATE TABLE NEW ("
|
||||||
+ KEY_TIMESTAMP + " INT,"
|
+ KEY_TIMESTAMP + " INT,"
|
||||||
+ KEY_PROVIDER + " TINYINT,"
|
+ KEY_PROVIDER + " TINYINT,"
|
||||||
@ -64,8 +65,8 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper {
|
|||||||
+ KEY_TYPE + " TINYINT,"
|
+ KEY_TYPE + " TINYINT,"
|
||||||
+ " PRIMARY KEY (" + KEY_TIMESTAMP + "," + KEY_PROVIDER + ") ON CONFLICT REPLACE)" + getWithoutRowId();
|
+ " PRIMARY KEY (" + KEY_TIMESTAMP + "," + KEY_PROVIDER + ") ON CONFLICT REPLACE)" + getWithoutRowId();
|
||||||
db.execSQL(CREATE_NEW_GBACTIVITYSAMPLES_TABLE);
|
db.execSQL(CREATE_NEW_GBACTIVITYSAMPLES_TABLE);
|
||||||
db.execSQL("insert into NEW select timestamp,provider,intensity,steps,type from "+ TABLE_GBACTIVITYSAMPLES+";");
|
db.execSQL("insert into NEW select timestamp,provider,intensity,steps,type from " + TABLE_GBACTIVITYSAMPLES + ";");
|
||||||
db.execSQL("Drop table "+TABLE_GBACTIVITYSAMPLES+";");
|
db.execSQL("Drop table " + TABLE_GBACTIVITYSAMPLES + ";");
|
||||||
db.execSQL("alter table NEW RENAME TO " + TABLE_GBACTIVITYSAMPLES + ";");
|
db.execSQL("alter table NEW RENAME TO " + TABLE_GBACTIVITYSAMPLES + ";");
|
||||||
} else {
|
} else {
|
||||||
//FIXME: do not just recreate
|
//FIXME: do not just recreate
|
||||||
|
@ -8,16 +8,14 @@ import android.bluetooth.BluetoothGattDescriptor;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.btle.BtLEAction;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.btle.NotifyAction;
|
import nodomain.freeyourgadget.gadgetbridge.btle.NotifyAction;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.btle.TransactionBuilder;
|
import nodomain.freeyourgadget.gadgetbridge.btle.TransactionBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.miband.MiBandService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables or disables notifications for a given GATT characteristic.
|
* Enables or disables notifications for a given GATT characteristic.
|
||||||
* The result will be made available asynchronously through the
|
* The result will be made available asynchronously through the
|
||||||
* {@link BluetoothGattCallback}.
|
* {@link BluetoothGattCallback}.
|
||||||
*
|
* <p/>
|
||||||
* This class is Mi Band specific.
|
* This class is Mi Band specific.
|
||||||
*/
|
*/
|
||||||
public class MiBandNotifyAction extends NotifyAction {
|
public class MiBandNotifyAction extends NotifyAction {
|
||||||
|
@ -128,7 +128,7 @@ public class MiBandService {
|
|||||||
public static final byte COMMAND_REBOOT = 0xc;
|
public static final byte COMMAND_REBOOT = 0xc;
|
||||||
|
|
||||||
public static final byte COMMAND_SEND_NOTIFICATION = 0x8;
|
public static final byte COMMAND_SEND_NOTIFICATION = 0x8;
|
||||||
|
|
||||||
public static final byte COMMAND_STOP_MOTOR_VIBRATE = 0x13;
|
public static final byte COMMAND_STOP_MOTOR_VIBRATE = 0x13;
|
||||||
|
|
||||||
public static final byte COMMAND_CONFIRM_ACTIVITY_DATA_TRANSFER_COMPLETE = 0xa;
|
public static final byte COMMAND_CONFIRM_ACTIVITY_DATA_TRANSFER_COMPLETE = 0xa;
|
||||||
|
@ -86,6 +86,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
* Last action of initialization sequence. Sets the device to initialized.
|
* Last action of initialization sequence. Sets the device to initialized.
|
||||||
* It is only invoked if all other actions were successfully run, so the device
|
* It is only invoked if all other actions were successfully run, so the device
|
||||||
* must be initialized, then.
|
* must be initialized, then.
|
||||||
|
*
|
||||||
* @param builder
|
* @param builder
|
||||||
*/
|
*/
|
||||||
private void setInitialized(TransactionBuilder builder) {
|
private void setInitialized(TransactionBuilder builder) {
|
||||||
@ -150,10 +151,10 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
builder.queue(getQueue());
|
builder.queue(getQueue());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final byte[] startVibrate = new byte[] { MiBandService.COMMAND_SEND_NOTIFICATION, 1 };
|
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[] stopVibrate = new byte[]{MiBandService.COMMAND_STOP_MOTOR_VIBRATE};
|
||||||
private static final byte[] reboot = new byte[]{ MiBandService.COMMAND_REBOOT };
|
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[] fetch = new byte[]{MiBandService.COMMAND_FETCH_DATA};
|
||||||
|
|
||||||
private byte[] getNotification(long vibrateDuration, int vibrateTimes, int flashTimes, int flashColour, int originalColour, long flashDuration) {
|
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};
|
byte[] vibrate = new byte[]{MiBandService.COMMAND_SEND_NOTIFICATION, (byte) 1};
|
||||||
@ -452,11 +453,11 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleActivityNotif(byte[] value) {
|
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
|
// byte 0 is the data type: 1 means that each minute is represented by a triplet of bytes
|
||||||
int dataType = value[0];
|
int dataType = value[0];
|
||||||
// byte 1 to 6 represent a timestamp
|
// byte 1 to 6 represent a timestamp
|
||||||
GregorianCalendar timestamp = new GregorianCalendar(value[1]+2000,
|
GregorianCalendar timestamp = new GregorianCalendar(value[1] + 2000,
|
||||||
value[2],
|
value[2],
|
||||||
value[3],
|
value[3],
|
||||||
value[4],
|
value[4],
|
||||||
@ -470,15 +471,15 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
|
|
||||||
// counter of this data block
|
// counter of this data block
|
||||||
int dataUntilNextHeader = (value[9] & 0xff) | ((value[10] & 0xff) << 8);
|
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),
|
// 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
|
// 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
|
// after dataUntilNextHeader bytes we will get a new packet of 11 bytes that should be parsed
|
||||||
// as we just did
|
// as we just did
|
||||||
|
|
||||||
LOG.info("total data to read: "+ totalDataToRead +" len: " + (totalDataToRead / 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("data to read until next header: " + dataUntilNextHeader + " len: " + (dataUntilNextHeader / 3) + " minute(s)");
|
||||||
LOG.info("TIMESTAMP: " + DateFormat.getDateTimeInstance().format(timestamp.getTime()).toString() + " magic byte: " + dataUntilNextHeader);
|
LOG.info("TIMESTAMP: " + DateFormat.getDateTimeInstance().format(timestamp.getTime()).toString() + " magic byte: " + dataUntilNextHeader);
|
||||||
|
|
||||||
this.activityDataRemainingBytes = this.activityDataUntilNextHeader = 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
|
//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) {
|
if (value.length == 20 || value.length == this.activityDataRemainingBytes) {
|
||||||
System.arraycopy(value, 0, this.activityDataHolder, this.activityDataHolderProgress, value.length);
|
System.arraycopy(value, 0, this.activityDataHolder, this.activityDataHolderProgress, value.length);
|
||||||
this.activityDataHolderProgress +=value.length;
|
this.activityDataHolderProgress += value.length;
|
||||||
this.activityDataRemainingBytes -= value.length;
|
this.activityDataRemainingBytes -= value.length;
|
||||||
|
|
||||||
if (this.activityDataHolderSize == this.activityDataHolderProgress) {
|
if (this.activityDataHolderSize == this.activityDataHolderProgress) {
|
||||||
@ -508,7 +509,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
} else {
|
} else {
|
||||||
// the length of the chunk is not what we expect. We need to make sense of this data
|
// 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);
|
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));
|
LOG.warn("DATA: " + String.format("0x%8x", b));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -521,10 +522,10 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
|
|
||||||
ActivityDatabaseHandler dbHandler = GBApplication.getActivityDatabaseHandler();
|
ActivityDatabaseHandler dbHandler = GBApplication.getActivityDatabaseHandler();
|
||||||
try (SQLiteDatabase db = dbHandler.getWritableDatabase()) { // explicitly keep the db open while looping over the samples
|
try (SQLiteDatabase db = dbHandler.getWritableDatabase()) { // explicitly keep the db open while looping over the samples
|
||||||
for (int i=0; i<this.activityDataHolderProgress; i+=3) { //TODO: check if multiple of 3, if not something is wrong
|
for (int i = 0; i < this.activityDataHolderProgress; i += 3) { //TODO: check if multiple of 3, if not something is wrong
|
||||||
category = this.activityDataHolder[i];
|
category = this.activityDataHolder[i];
|
||||||
intensity = this.activityDataHolder[i+1];
|
intensity = this.activityDataHolder[i + 1];
|
||||||
steps = this.activityDataHolder[i+2];
|
steps = this.activityDataHolder[i + 2];
|
||||||
|
|
||||||
dbHandler.addGBActivitySample(
|
dbHandler.addGBActivitySample(
|
||||||
(int) (timestamp.getTimeInMillis() / 1000),
|
(int) (timestamp.getTimeInMillis() / 1000),
|
||||||
@ -551,7 +552,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
unsetBusy();
|
unsetBusy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (byte b: value){
|
for (byte b : value) {
|
||||||
LOG.info("handleControlPoint GOT DATA:" + String.format("0x%8x", b));
|
LOG.info("handleControlPoint GOT DATA:" + String.format("0x%8x", b));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import android.bluetooth.BluetoothGatt;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.btle.BtLEAction;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.btle.PlainAction;
|
import nodomain.freeyourgadget.gadgetbridge.btle.PlainAction;
|
||||||
|
|
||||||
public class SetDeviceStateAction extends PlainAction {
|
public class SetDeviceStateAction extends PlainAction {
|
||||||
|
Loading…
Reference in New Issue
Block a user