Let GallCallback return boolean values in order to mark an event as "consumed"
(to avoid dispatching the event to further listeners (ble profiles)master
parent
c9a9566dad
commit
b43b7948b0
|
@ -200,41 +200,56 @@ public abstract class AbstractBTLEDeviceSupport extends AbstractDeviceSupport im
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicRead(BluetoothGatt gatt,
|
public boolean onCharacteristicRead(BluetoothGatt gatt,
|
||||||
BluetoothGattCharacteristic characteristic, int status) {
|
BluetoothGattCharacteristic characteristic, int status) {
|
||||||
for (AbstractBleProfile profile : mSupportedProfiles) {
|
for (AbstractBleProfile profile : mSupportedProfiles) {
|
||||||
profile.onCharacteristicRead(gatt, characteristic, status);
|
if (profile.onCharacteristicRead(gatt, characteristic, status)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicWrite(BluetoothGatt gatt,
|
public boolean onCharacteristicWrite(BluetoothGatt gatt,
|
||||||
BluetoothGattCharacteristic characteristic, int status) {
|
BluetoothGattCharacteristic characteristic, int status) {
|
||||||
for (AbstractBleProfile profile : mSupportedProfiles) {
|
for (AbstractBleProfile profile : mSupportedProfiles) {
|
||||||
profile.onCharacteristicWrite(gatt, characteristic, status);
|
if (profile.onCharacteristicWrite(gatt, characteristic, status)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
public boolean onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
||||||
for (AbstractBleProfile profile : mSupportedProfiles) {
|
for (AbstractBleProfile profile : mSupportedProfiles) {
|
||||||
profile.onDescriptorRead(gatt, descriptor, status);
|
if (profile.onDescriptorRead(gatt, descriptor, status)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
public boolean onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
||||||
for (AbstractBleProfile profile : mSupportedProfiles) {
|
for (AbstractBleProfile profile : mSupportedProfiles) {
|
||||||
profile.onDescriptorWrite(gatt, descriptor, status);
|
if (profile.onDescriptorWrite(gatt, descriptor, status)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicChanged(BluetoothGatt gatt,
|
public boolean onCharacteristicChanged(BluetoothGatt gatt,
|
||||||
BluetoothGattCharacteristic characteristic) {
|
BluetoothGattCharacteristic characteristic) {
|
||||||
for (AbstractBleProfile profile : mSupportedProfiles) {
|
for (AbstractBleProfile profile : mSupportedProfiles) {
|
||||||
profile.onCharacteristicChanged(gatt, characteristic);
|
if (profile.onCharacteristicChanged(gatt, characteristic)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -135,28 +135,28 @@ public abstract class AbstractBTLEOperation<T extends AbstractBTLEDeviceSupport>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
|
public boolean onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
|
||||||
mSupport.onCharacteristicRead(gatt, characteristic, status);
|
return mSupport.onCharacteristicRead(gatt, characteristic, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
|
public boolean onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
|
||||||
mSupport.onCharacteristicWrite(gatt, characteristic, status);
|
return mSupport.onCharacteristicWrite(gatt, characteristic, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
|
public boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
|
||||||
mSupport.onCharacteristicChanged(gatt, characteristic);
|
return mSupport.onCharacteristicChanged(gatt, characteristic);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
public boolean onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
||||||
mSupport.onDescriptorRead(gatt, descriptor, status);
|
return mSupport.onDescriptorRead(gatt, descriptor, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
public boolean onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
||||||
mSupport.onDescriptorWrite(gatt, descriptor, status);
|
return mSupport.onDescriptorWrite(gatt, descriptor, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,23 +17,28 @@ public abstract class AbstractGattCallback implements GattCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
|
public boolean onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
|
public boolean onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
|
public boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
public boolean onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
public boolean onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,6 +25,10 @@ import android.bluetooth.BluetoothGattDescriptor;
|
||||||
* Callback interface handling gatt events.
|
* Callback interface handling gatt events.
|
||||||
* Pretty much the same as {@link BluetoothGattCallback}, except it's an interface
|
* Pretty much the same as {@link BluetoothGattCallback}, except it's an interface
|
||||||
* instead of an abstract class. Some handlers commented out, because not used (yet).
|
* instead of an abstract class. Some handlers commented out, because not used (yet).
|
||||||
|
*
|
||||||
|
* Note: the boolean return values indicate whether this callback "consumed" this event
|
||||||
|
* or not. True means, the event was consumed by this instance and no further instances
|
||||||
|
* shall be notified. Fallse means, this instance could not handle the event.
|
||||||
*/
|
*/
|
||||||
public interface GattCallback {
|
public interface GattCallback {
|
||||||
|
|
||||||
|
@ -48,7 +52,7 @@ public interface GattCallback {
|
||||||
* @param status
|
* @param status
|
||||||
* @see BluetoothGattCallback#onCharacteristicRead(BluetoothGatt, BluetoothGattCharacteristic, int)
|
* @see BluetoothGattCallback#onCharacteristicRead(BluetoothGatt, BluetoothGattCharacteristic, int)
|
||||||
*/
|
*/
|
||||||
void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status);
|
boolean onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param gatt
|
* @param gatt
|
||||||
|
@ -56,7 +60,7 @@ public interface GattCallback {
|
||||||
* @param status
|
* @param status
|
||||||
* @see BluetoothGattCallback#onCharacteristicWrite(BluetoothGatt, BluetoothGattCharacteristic, int)
|
* @see BluetoothGattCallback#onCharacteristicWrite(BluetoothGatt, BluetoothGattCharacteristic, int)
|
||||||
*/
|
*/
|
||||||
void onCharacteristicWrite(BluetoothGatt gatt,
|
boolean onCharacteristicWrite(BluetoothGatt gatt,
|
||||||
BluetoothGattCharacteristic characteristic, int status);
|
BluetoothGattCharacteristic characteristic, int status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,7 +68,7 @@ public interface GattCallback {
|
||||||
* @param characteristic
|
* @param characteristic
|
||||||
* @see BluetoothGattCallback#onCharacteristicChanged(BluetoothGatt, BluetoothGattCharacteristic)
|
* @see BluetoothGattCallback#onCharacteristicChanged(BluetoothGatt, BluetoothGattCharacteristic)
|
||||||
*/
|
*/
|
||||||
void onCharacteristicChanged(BluetoothGatt gatt,
|
boolean onCharacteristicChanged(BluetoothGatt gatt,
|
||||||
BluetoothGattCharacteristic characteristic);
|
BluetoothGattCharacteristic characteristic);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,7 +77,7 @@ public interface GattCallback {
|
||||||
* @param status
|
* @param status
|
||||||
* @see BluetoothGattCallback#onDescriptorRead(BluetoothGatt, BluetoothGattDescriptor, int)
|
* @see BluetoothGattCallback#onDescriptorRead(BluetoothGatt, BluetoothGattDescriptor, int)
|
||||||
*/
|
*/
|
||||||
void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
|
boolean onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
|
||||||
int status);
|
int status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,7 +86,7 @@ public interface GattCallback {
|
||||||
* @param status
|
* @param status
|
||||||
* @see BluetoothGattCallback#onDescriptorWrite(BluetoothGatt, BluetoothGattDescriptor, int)
|
* @see BluetoothGattCallback#onDescriptorWrite(BluetoothGatt, BluetoothGattDescriptor, int)
|
||||||
*/
|
*/
|
||||||
void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
|
boolean onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
|
||||||
int status);
|
int status);
|
||||||
//
|
//
|
||||||
// /**
|
// /**
|
||||||
|
|
|
@ -7,7 +7,6 @@ import android.content.Intent;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
|
||||||
|
@ -43,17 +42,19 @@ public class BatteryInfoProfile<T extends AbstractBTLEDeviceSupport> extends Abs
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
|
public boolean onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
|
||||||
if (status == BluetoothGatt.GATT_SUCCESS) {
|
if (status == BluetoothGatt.GATT_SUCCESS) {
|
||||||
UUID charUuid = characteristic.getUuid();
|
UUID charUuid = characteristic.getUuid();
|
||||||
if (charUuid.equals(UUID_CHARACTERISTIC_BATTERY_LEVEL)) {
|
if (charUuid.equals(UUID_CHARACTERISTIC_BATTERY_LEVEL)) {
|
||||||
handleBatteryLevel(gatt, characteristic);
|
handleBatteryLevel(gatt, characteristic);
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
LOG.info("Unexpected onCharacteristicRead: " + GattCharacteristic.toString(characteristic));
|
LOG.info("Unexpected onCharacteristicRead: " + GattCharacteristic.toString(characteristic));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.warn("error reading from characteristic:" + GattCharacteristic.toString(characteristic));
|
LOG.warn("error reading from characteristic:" + GattCharacteristic.toString(characteristic));
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleBatteryLevel(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
|
private void handleBatteryLevel(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
|
||||||
|
|
|
@ -7,7 +7,6 @@ import android.content.Intent;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
|
||||||
|
@ -15,7 +14,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.GattCharacteristic;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.AbstractBleProfile;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.AbstractBleProfile;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.battery.BatteryInfo;
|
|
||||||
|
|
||||||
public class DeviceInfoProfile<T extends AbstractBTLEDeviceSupport> extends AbstractBleProfile {
|
public class DeviceInfoProfile<T extends AbstractBTLEDeviceSupport> extends AbstractBleProfile {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(DeviceInfoProfile.class);
|
private static final Logger LOG = LoggerFactory.getLogger(DeviceInfoProfile.class);
|
||||||
|
@ -55,33 +53,43 @@ public class DeviceInfoProfile<T extends AbstractBTLEDeviceSupport> extends Abst
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
|
public boolean onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
|
||||||
if (status == BluetoothGatt.GATT_SUCCESS) {
|
if (status == BluetoothGatt.GATT_SUCCESS) {
|
||||||
UUID charUuid = characteristic.getUuid();
|
UUID charUuid = characteristic.getUuid();
|
||||||
if (charUuid.equals(UUID_CHARACTERISTIC_MANUFACTURER_NAME_STRING)) {
|
if (charUuid.equals(UUID_CHARACTERISTIC_MANUFACTURER_NAME_STRING)) {
|
||||||
handleManufacturerName(gatt, characteristic);
|
handleManufacturerName(gatt, characteristic);
|
||||||
|
return true;
|
||||||
} else if (charUuid.equals(UUID_CHARACTERISTIC_MODEL_NUMBER_STRING)) {
|
} else if (charUuid.equals(UUID_CHARACTERISTIC_MODEL_NUMBER_STRING)) {
|
||||||
handleModelNumber(gatt, characteristic);
|
handleModelNumber(gatt, characteristic);
|
||||||
|
return true;
|
||||||
} else if (charUuid.equals(UUID_CHARACTERISTIC_SERIAL_NUMBER_STRING)) {
|
} else if (charUuid.equals(UUID_CHARACTERISTIC_SERIAL_NUMBER_STRING)) {
|
||||||
handleSerialNumber(gatt, characteristic);
|
handleSerialNumber(gatt, characteristic);
|
||||||
|
return true;
|
||||||
} else if (charUuid.equals(UUID_CHARACTERISTIC_HARDWARE_REVISION_STRING)) {
|
} else if (charUuid.equals(UUID_CHARACTERISTIC_HARDWARE_REVISION_STRING)) {
|
||||||
handleHardwareRevision(gatt, characteristic);
|
handleHardwareRevision(gatt, characteristic);
|
||||||
|
return true;
|
||||||
} else if (charUuid.equals(UUID_CHARACTERISTIC_FIRMWARE_REVISION_STRING)) {
|
} else if (charUuid.equals(UUID_CHARACTERISTIC_FIRMWARE_REVISION_STRING)) {
|
||||||
handleFirmwareRevision(gatt, characteristic);
|
handleFirmwareRevision(gatt, characteristic);
|
||||||
|
return true;
|
||||||
} else if (charUuid.equals(UUID_CHARACTERISTIC_SOFTWARE_REVISION_STRING)) {
|
} else if (charUuid.equals(UUID_CHARACTERISTIC_SOFTWARE_REVISION_STRING)) {
|
||||||
handleSoftwareRevision(gatt, characteristic);
|
handleSoftwareRevision(gatt, characteristic);
|
||||||
|
return true;
|
||||||
} else if (charUuid.equals(UUID_CHARACTERISTIC_SYSTEM_ID)) {
|
} else if (charUuid.equals(UUID_CHARACTERISTIC_SYSTEM_ID)) {
|
||||||
handleSystemId(gatt, characteristic);
|
handleSystemId(gatt, characteristic);
|
||||||
|
return true;
|
||||||
} else if (charUuid.equals(UUID_CHARACTERISTIC_IEEE_11073_20601_REGULATORY_CERTIFICATION_DATA_LIST)) {
|
} else if (charUuid.equals(UUID_CHARACTERISTIC_IEEE_11073_20601_REGULATORY_CERTIFICATION_DATA_LIST)) {
|
||||||
handleRegulatoryCertificationData(gatt, characteristic);
|
handleRegulatoryCertificationData(gatt, characteristic);
|
||||||
|
return true;
|
||||||
} else if (charUuid.equals(UUID_CHARACTERISTIC_PNP_ID)) {
|
} else if (charUuid.equals(UUID_CHARACTERISTIC_PNP_ID)) {
|
||||||
handlePnpId(gatt, characteristic);
|
handlePnpId(gatt, characteristic);
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
LOG.info("Unexpected onCharacteristicRead: " + GattCharacteristic.toString(characteristic));
|
LOG.info("Unexpected onCharacteristicRead: " + GattCharacteristic.toString(characteristic));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.warn("error reading from characteristic:" + GattCharacteristic.toString(characteristic));
|
LOG.warn("error reading from characteristic:" + GattCharacteristic.toString(characteristic));
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -824,60 +824,76 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicChanged(BluetoothGatt gatt,
|
public boolean onCharacteristicChanged(BluetoothGatt gatt,
|
||||||
BluetoothGattCharacteristic characteristic) {
|
BluetoothGattCharacteristic characteristic) {
|
||||||
super.onCharacteristicChanged(gatt, characteristic);
|
super.onCharacteristicChanged(gatt, characteristic);
|
||||||
|
|
||||||
UUID characteristicUUID = characteristic.getUuid();
|
UUID characteristicUUID = characteristic.getUuid();
|
||||||
if (MiBandService.UUID_CHARACTERISTIC_BATTERY.equals(characteristicUUID)) {
|
if (MiBandService.UUID_CHARACTERISTIC_BATTERY.equals(characteristicUUID)) {
|
||||||
handleBatteryInfo(characteristic.getValue(), BluetoothGatt.GATT_SUCCESS);
|
handleBatteryInfo(characteristic.getValue(), BluetoothGatt.GATT_SUCCESS);
|
||||||
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_NOTIFICATION.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_NOTIFICATION.equals(characteristicUUID)) {
|
||||||
handleNotificationNotif(characteristic.getValue());
|
handleNotificationNotif(characteristic.getValue());
|
||||||
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS.equals(characteristicUUID)) {
|
||||||
handleRealtimeSteps(characteristic.getValue());
|
handleRealtimeSteps(characteristic.getValue());
|
||||||
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS.equals(characteristicUUID)) {
|
||||||
handleRealtimeSteps(characteristic.getValue());
|
handleRealtimeSteps(characteristic.getValue());
|
||||||
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) {
|
||||||
handleHeartrate(characteristic.getValue());
|
handleHeartrate(characteristic.getValue());
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
LOG.info("Unhandled characteristic changed: " + characteristicUUID);
|
LOG.info("Unhandled characteristic changed: " + characteristicUUID);
|
||||||
logMessageContent(characteristic.getValue());
|
logMessageContent(characteristic.getValue());
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicRead(BluetoothGatt gatt,
|
public boolean onCharacteristicRead(BluetoothGatt gatt,
|
||||||
BluetoothGattCharacteristic characteristic, int status) {
|
BluetoothGattCharacteristic characteristic, int status) {
|
||||||
super.onCharacteristicRead(gatt, characteristic, status);
|
super.onCharacteristicRead(gatt, characteristic, status);
|
||||||
|
|
||||||
UUID characteristicUUID = characteristic.getUuid();
|
UUID characteristicUUID = characteristic.getUuid();
|
||||||
if (MiBandService.UUID_CHARACTERISTIC_DEVICE_INFO.equals(characteristicUUID)) {
|
if (MiBandService.UUID_CHARACTERISTIC_DEVICE_INFO.equals(characteristicUUID)) {
|
||||||
handleDeviceInfo(characteristic.getValue(), status);
|
handleDeviceInfo(characteristic.getValue(), status);
|
||||||
|
return true;
|
||||||
} else if (GattCharacteristic.UUID_CHARACTERISTIC_GAP_DEVICE_NAME.equals(characteristicUUID)) {
|
} else if (GattCharacteristic.UUID_CHARACTERISTIC_GAP_DEVICE_NAME.equals(characteristicUUID)) {
|
||||||
handleDeviceName(characteristic.getValue(), status);
|
handleDeviceName(characteristic.getValue(), status);
|
||||||
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_BATTERY.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_BATTERY.equals(characteristicUUID)) {
|
||||||
handleBatteryInfo(characteristic.getValue(), status);
|
handleBatteryInfo(characteristic.getValue(), status);
|
||||||
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) {
|
||||||
logHeartrate(characteristic.getValue(), status);
|
logHeartrate(characteristic.getValue(), status);
|
||||||
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_DATE_TIME.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_DATE_TIME.equals(characteristicUUID)) {
|
||||||
logDate(characteristic.getValue(), status);
|
logDate(characteristic.getValue(), status);
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
LOG.info("Unhandled characteristic read: " + characteristicUUID);
|
LOG.info("Unhandled characteristic read: " + characteristicUUID);
|
||||||
logMessageContent(characteristic.getValue());
|
logMessageContent(characteristic.getValue());
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicWrite(BluetoothGatt gatt,
|
public boolean onCharacteristicWrite(BluetoothGatt gatt,
|
||||||
BluetoothGattCharacteristic characteristic, int status) {
|
BluetoothGattCharacteristic characteristic, int status) {
|
||||||
UUID characteristicUUID = characteristic.getUuid();
|
UUID characteristicUUID = characteristic.getUuid();
|
||||||
if (MiBandService.UUID_CHARACTERISTIC_PAIR.equals(characteristicUUID)) {
|
if (MiBandService.UUID_CHARACTERISTIC_PAIR.equals(characteristicUUID)) {
|
||||||
handlePairResult(characteristic.getValue(), status);
|
handlePairResult(characteristic.getValue(), status);
|
||||||
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_USER_INFO.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_USER_INFO.equals(characteristicUUID)) {
|
||||||
handleUserInfoResult(characteristic.getValue(), status);
|
handleUserInfoResult(characteristic.getValue(), status);
|
||||||
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT.equals(characteristicUUID)) {
|
||||||
handleControlPointResult(characteristic.getValue(), status);
|
handleControlPointResult(characteristic.getValue(), status);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -785,60 +785,76 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicChanged(BluetoothGatt gatt,
|
public boolean onCharacteristicChanged(BluetoothGatt gatt,
|
||||||
BluetoothGattCharacteristic characteristic) {
|
BluetoothGattCharacteristic characteristic) {
|
||||||
super.onCharacteristicChanged(gatt, characteristic);
|
super.onCharacteristicChanged(gatt, characteristic);
|
||||||
|
|
||||||
UUID characteristicUUID = characteristic.getUuid();
|
UUID characteristicUUID = characteristic.getUuid();
|
||||||
if (MiBandService.UUID_CHARACTERISTIC_BATTERY.equals(characteristicUUID)) {
|
if (MiBandService.UUID_CHARACTERISTIC_BATTERY.equals(characteristicUUID)) {
|
||||||
handleBatteryInfo(characteristic.getValue(), BluetoothGatt.GATT_SUCCESS);
|
handleBatteryInfo(characteristic.getValue(), BluetoothGatt.GATT_SUCCESS);
|
||||||
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_NOTIFICATION.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_NOTIFICATION.equals(characteristicUUID)) {
|
||||||
handleNotificationNotif(characteristic.getValue());
|
handleNotificationNotif(characteristic.getValue());
|
||||||
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS.equals(characteristicUUID)) {
|
||||||
handleRealtimeSteps(characteristic.getValue());
|
handleRealtimeSteps(characteristic.getValue());
|
||||||
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS.equals(characteristicUUID)) {
|
||||||
handleRealtimeSteps(characteristic.getValue());
|
handleRealtimeSteps(characteristic.getValue());
|
||||||
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) {
|
||||||
handleHeartrate(characteristic.getValue());
|
handleHeartrate(characteristic.getValue());
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
LOG.info("Unhandled characteristic changed: " + characteristicUUID);
|
LOG.info("Unhandled characteristic changed: " + characteristicUUID);
|
||||||
logMessageContent(characteristic.getValue());
|
logMessageContent(characteristic.getValue());
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicRead(BluetoothGatt gatt,
|
public boolean onCharacteristicRead(BluetoothGatt gatt,
|
||||||
BluetoothGattCharacteristic characteristic, int status) {
|
BluetoothGattCharacteristic characteristic, int status) {
|
||||||
super.onCharacteristicRead(gatt, characteristic, status);
|
super.onCharacteristicRead(gatt, characteristic, status);
|
||||||
|
|
||||||
UUID characteristicUUID = characteristic.getUuid();
|
UUID characteristicUUID = characteristic.getUuid();
|
||||||
if (MiBandService.UUID_CHARACTERISTIC_DEVICE_INFO.equals(characteristicUUID)) {
|
if (MiBandService.UUID_CHARACTERISTIC_DEVICE_INFO.equals(characteristicUUID)) {
|
||||||
handleDeviceInfo(characteristic.getValue(), status);
|
handleDeviceInfo(characteristic.getValue(), status);
|
||||||
|
return true;
|
||||||
} else if (GattCharacteristic.UUID_CHARACTERISTIC_GAP_DEVICE_NAME.equals(characteristicUUID)) {
|
} else if (GattCharacteristic.UUID_CHARACTERISTIC_GAP_DEVICE_NAME.equals(characteristicUUID)) {
|
||||||
handleDeviceName(characteristic.getValue(), status);
|
handleDeviceName(characteristic.getValue(), status);
|
||||||
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_BATTERY.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_BATTERY.equals(characteristicUUID)) {
|
||||||
handleBatteryInfo(characteristic.getValue(), status);
|
handleBatteryInfo(characteristic.getValue(), status);
|
||||||
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) {
|
||||||
logHeartrate(characteristic.getValue(), status);
|
logHeartrate(characteristic.getValue(), status);
|
||||||
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_DATE_TIME.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_DATE_TIME.equals(characteristicUUID)) {
|
||||||
logDate(characteristic.getValue(), status);
|
logDate(characteristic.getValue(), status);
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
LOG.info("Unhandled characteristic read: " + characteristicUUID);
|
LOG.info("Unhandled characteristic read: " + characteristicUUID);
|
||||||
logMessageContent(characteristic.getValue());
|
logMessageContent(characteristic.getValue());
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicWrite(BluetoothGatt gatt,
|
public boolean onCharacteristicWrite(BluetoothGatt gatt,
|
||||||
BluetoothGattCharacteristic characteristic, int status) {
|
BluetoothGattCharacteristic characteristic, int status) {
|
||||||
UUID characteristicUUID = characteristic.getUuid();
|
UUID characteristicUUID = characteristic.getUuid();
|
||||||
if (MiBandService.UUID_CHARACTERISTIC_PAIR.equals(characteristicUUID)) {
|
if (MiBandService.UUID_CHARACTERISTIC_PAIR.equals(characteristicUUID)) {
|
||||||
handlePairResult(characteristic.getValue(), status);
|
handlePairResult(characteristic.getValue(), status);
|
||||||
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_USER_INFO.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_USER_INFO.equals(characteristicUUID)) {
|
||||||
handleUserInfoResult(characteristic.getValue(), status);
|
handleUserInfoResult(characteristic.getValue(), status);
|
||||||
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT.equals(characteristicUUID)) {
|
||||||
handleControlPointResult(characteristic.getValue(), status);
|
handleControlPointResult(characteristic.getValue(), status);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -151,13 +151,14 @@ public class FetchActivityOperation extends AbstractMiBandOperation {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicChanged(BluetoothGatt gatt,
|
public boolean onCharacteristicChanged(BluetoothGatt gatt,
|
||||||
BluetoothGattCharacteristic characteristic) {
|
BluetoothGattCharacteristic characteristic) {
|
||||||
UUID characteristicUUID = characteristic.getUuid();
|
UUID characteristicUUID = characteristic.getUuid();
|
||||||
if (MiBandService.UUID_CHARACTERISTIC_ACTIVITY_DATA.equals(characteristicUUID)) {
|
if (MiBandService.UUID_CHARACTERISTIC_ACTIVITY_DATA.equals(characteristicUUID)) {
|
||||||
handleActivityNotif(characteristic.getValue());
|
handleActivityNotif(characteristic.getValue());
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
super.onCharacteristicChanged(gatt, characteristic);
|
return super.onCharacteristicChanged(gatt, characteristic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,14 +72,15 @@ public class UpdateFirmwareOperation extends AbstractMiBandOperation {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicChanged(BluetoothGatt gatt,
|
public boolean onCharacteristicChanged(BluetoothGatt gatt,
|
||||||
BluetoothGattCharacteristic characteristic) {
|
BluetoothGattCharacteristic characteristic) {
|
||||||
UUID characteristicUUID = characteristic.getUuid();
|
UUID characteristicUUID = characteristic.getUuid();
|
||||||
if (MiBandService.UUID_CHARACTERISTIC_NOTIFICATION.equals(characteristicUUID)) {
|
if (MiBandService.UUID_CHARACTERISTIC_NOTIFICATION.equals(characteristicUUID)) {
|
||||||
handleNotificationNotif(characteristic.getValue());
|
handleNotificationNotif(characteristic.getValue());
|
||||||
} else {
|
} else {
|
||||||
super.onCharacteristicChanged(gatt, characteristic);
|
super.onCharacteristicChanged(gatt, characteristic);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue