1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-25 19:36:50 +01:00

Fossil HR: added timeout to on-device confirmation

This commit is contained in:
Daniel Dakhno 2021-12-13 03:04:44 +01:00
parent dbdeb59f9c
commit 45647ccbf7
2 changed files with 31 additions and 14 deletions

View File

@ -91,7 +91,7 @@ import static nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybr
public class FossilWatchAdapter extends WatchAdapter {
private ArrayList<Request> requestQueue = new ArrayList<>();
private FossilRequest fossilRequest;
protected FossilRequest fossilRequest;
private int MTU = 23;

View File

@ -62,6 +62,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -227,22 +229,37 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
confirmOnWatch();
}
TimerTask confirmTimeoutRunnable = new TimerTask() {
@Override
public void run() {
if (!(fossilRequest instanceof ConfirmOnDeviceRequest)) {
return;
}
GB.toast("Confirmation timeout, continuing", Toast.LENGTH_SHORT, GB.INFO);
((ConfirmOnDeviceRequest) fossilRequest).onResult(false);
}
};
private void confirmOnWatch() {
queueWrite(new CheckDeviceNeedsConfirmationRequest() {
@Override
public void onResult(boolean needsConfirmation) {
GB.log("needs confirmation: " + needsConfirmation, GB.INFO, null);
if (needsConfirmation) {
final Timer timer = new Timer();
GB.toast("please confirm on device.", Toast.LENGTH_SHORT, GB.INFO);
queueWrite(new ConfirmOnDeviceRequest() {
@Override
public void onResult(boolean confirmationSuccess) {
isFinished = true;
timer.cancel();
if (!confirmationSuccess) {
GB.toast("connection unconfirmed on watch, unauthenticated mode", Toast.LENGTH_LONG, GB.ERROR);
}
initializeAfterWatchConfirmation(confirmationSuccess);
}
}, true);
timer.schedule(confirmTimeoutRunnable, 30000);
} else {
initializeAfterWatchConfirmation(true);
}