From 32d5ceb78fcc108d1d4b142f5e50239e7caa2cb1 Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Mon, 25 Sep 2017 23:23:20 +0200 Subject: [PATCH] Make update notification dismissable on error conditions good idea, @joserebelo #821 --- .../operations/UpdateFirmwareOperation.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/operations/UpdateFirmwareOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/operations/UpdateFirmwareOperation.java index 742bb174..a616b8bd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/operations/UpdateFirmwareOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/operations/UpdateFirmwareOperation.java @@ -91,6 +91,18 @@ public class UpdateFirmwareOperation extends AbstractMiBand2Operation { unsetBusy(); } + @Override + public boolean onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { + if (status != BluetoothGatt.GATT_SUCCESS) { + operationFailed(); + } + return super.onCharacteristicWrite(gatt, characteristic, status); + } + + private void operationFailed() { + GB.updateInstallNotification(getContext().getString(R.string.updatefirmwareoperation_write_failed), false, 0, getContext()); + } + @Override public boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { @@ -154,6 +166,7 @@ public class UpdateFirmwareOperation extends AbstractMiBand2Operation { default: { LOG.error("Unexpected response during firmware update: "); getSupport().logMessageContent(value); + operationFailed(); displayMessage(getContext(), getContext().getString(R.string.updatefirmwareoperation_updateproblem_do_not_reboot), Toast.LENGTH_LONG, GB.ERROR); done(); return; @@ -165,6 +178,7 @@ public class UpdateFirmwareOperation extends AbstractMiBand2Operation { } } else { LOG.error("Unexpected notification during firmware update: "); + operationFailed(); getSupport().logMessageContent(value); displayMessage(getContext(), getContext().getString(R.string.updatefirmwareoperation_metadata_updateproblem), Toast.LENGTH_LONG, GB.ERROR); done();