From a923766aa591a098215d72ebce3f2aacdd341781 Mon Sep 17 00:00:00 2001 From: Patrick Rudolph Date: Sat, 28 Sep 2024 19:58:56 +0200 Subject: [PATCH] huawei: Improve user feedback in error cases Currently the user isn't informed about errors when connecting to the watch and is left with a working BT connection that isn't used at all. Add toasts when the HiChainRequest fails or times out and disconnect the phone. Without a successful HiChain established the connection is useless anyways and it causes the phone to be not discoverable any more. In addition add a timeout to the HiChainRequest, one longer for the first pairing, where the user needs to confirm the pairing request on the watch. The short delay is used for subsequent HiChainRequests. The watch might not answer HiChainRequests when it was paired with a different phone, so the added timeout and toast improves user experience a lot since it's now clear that there was a problem. Related to issue #4148 Related to issue #4061 Fixes issue #4062 Signed-off-by: Patrick Rudolph --- .../devices/huawei/HuaweiSupportProvider.java | 20 +++++++++++++++++++ .../huawei/requests/GetHiChainRequest.java | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java index 5d7015a6f..faa73665e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java @@ -494,6 +494,26 @@ public class HuaweiSupportProvider { public void call() { initializeDeviceConfigure(); } + @Override + public void timeout(Request request) { + LOG.error("Authentication timed out"); + GB.toast(context, R.string.authentication_failed_negotiation, Toast.LENGTH_LONG, GB.ERROR); + // Disconnect as no communication can succeed after this point + final GBDevice device = getDevice(); + if (device != null) { + GBApplication.deviceService(device).disconnect(); + } + } + @Override + public void handleException(Request.ResponseParseException e) { + LOG.error("Authentication exception", e); + GB.toast(context, R.string.authentication_failed_negotiation, Toast.LENGTH_LONG, GB.ERROR); + // Disconnect as no communication can succeed after this point + final GBDevice device = getDevice(); + if (device != null) { + GBApplication.deviceService(device).disconnect(); + } + } }; protected void initializeDeviceHiChainMode(int authType) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetHiChainRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetHiChainRequest.java index c65727146..fd9ff201b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetHiChainRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetHiChainRequest.java @@ -53,13 +53,19 @@ public class GetHiChainRequest extends Request { private byte[] challenge = null; private byte[] psk = null; + // The user needs to confirm the pairing request on the device itself. + private final int firstAuthenticateTimeout = 30 * 1000; + private final int authenticateTimeout = 5000; public GetHiChainRequest(HuaweiSupportProvider support, boolean firstConnection) { super(support); this.serviceId = DeviceConfig.id; this.commandId = HiChain.id; if (firstConnection) { + setupTimeoutUntilNext(firstAuthenticateTimeout); operationCode = 0x01; + } else { + setupTimeoutUntilNext(authenticateTimeout); } this.step = 0x01; }