1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 13:26: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 { public class FossilWatchAdapter extends WatchAdapter {
private ArrayList<Request> requestQueue = new ArrayList<>(); private ArrayList<Request> requestQueue = new ArrayList<>();
private FossilRequest fossilRequest; protected FossilRequest fossilRequest;
private int MTU = 23; private int MTU = 23;

View File

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