Fix fw update notification being stuck at the end

Fixes #821
master
cpfeiffer 2017-09-25 00:03:40 +02:00
parent e28085e6af
commit 3c9fab0471
2 changed files with 11 additions and 2 deletions

View File

@ -687,13 +687,18 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
public void onReboot() { public void onReboot() {
try { try {
TransactionBuilder builder = performInitialized("Reboot"); TransactionBuilder builder = performInitialized("Reboot");
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_FIRMWARE), new byte[] { MiBand2Service.COMMAND_FIRMWARE_REBOOT}); sendReboot(builder);
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException ex) { } catch (IOException ex) {
LOG.error("Unable to reboot MI", ex); LOG.error("Unable to reboot MI", ex);
} }
} }
public MiBand2Support sendReboot(TransactionBuilder builder) {
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_FIRMWARE), new byte[] { MiBand2Service.COMMAND_FIRMWARE_REBOOT});
return this;
}
@Override @Override
public void onHeartRateTest() { public void onHeartRateTest() {
try { try {

View File

@ -97,6 +97,7 @@ public class UpdateFirmwareOperation extends AbstractMiBand2Operation {
UUID characteristicUUID = characteristic.getUuid(); UUID characteristicUUID = characteristic.getUuid();
if (fwCControlChar.getUuid().equals(characteristicUUID)) { if (fwCControlChar.getUuid().equals(characteristicUUID)) {
handleNotificationNotif(characteristic.getValue()); handleNotificationNotif(characteristic.getValue());
return true; // don't let anyone else handle it
} else { } else {
super.onCharacteristicChanged(gatt, characteristic); super.onCharacteristicChanged(gatt, characteristic);
} }
@ -134,7 +135,9 @@ public class UpdateFirmwareOperation extends AbstractMiBand2Operation {
} }
case MiBand2Service.COMMAND_FIRMWARE_CHECKSUM: { case MiBand2Service.COMMAND_FIRMWARE_CHECKSUM: {
if (getFirmwareInfo().getFirmwareType() == FirmwareType.FIRMWARE) { if (getFirmwareInfo().getFirmwareType() == FirmwareType.FIRMWARE) {
getSupport().onReboot(); TransactionBuilder builder = performInitialized("reboot");
getSupport().sendReboot(builder);
builder.queue(getQueue());
} else { } else {
GB.updateInstallNotification(getContext().getString(R.string.updatefirmwareoperation_update_complete), false, 100, getContext()); GB.updateInstallNotification(getContext().getString(R.string.updatefirmwareoperation_update_complete), false, 100, getContext());
done(); done();
@ -142,6 +145,7 @@ public class UpdateFirmwareOperation extends AbstractMiBand2Operation {
break; break;
} }
case MiBand2Service.COMMAND_FIRMWARE_REBOOT: { case MiBand2Service.COMMAND_FIRMWARE_REBOOT: {
LOG.info("Reboot command successfully sent.");
GB.updateInstallNotification(getContext().getString(R.string.updatefirmwareoperation_update_complete), false, 100, getContext()); GB.updateInstallNotification(getContext().getString(R.string.updatefirmwareoperation_update_complete), false, 100, getContext());
// getSupport().onReboot(); // getSupport().onReboot();
done(); done();