From 3dd286928395b88255bcb52b31038ad87a6afc8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20B=C3=B6hler?= Date: Mon, 9 Oct 2023 12:02:37 +0200 Subject: [PATCH] Fix first connect on the Casio GBX100/GBD-200 series --- .../gbx100/CasioGBX100DeviceSupport.java | 17 +++++++++++-- .../devices/casio/gbx100/InitOperation.java | 24 ++++++++++--------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/CasioGBX100DeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/CasioGBX100DeviceSupport.java index 7de247086..333c42721 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/CasioGBX100DeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/CasioGBX100DeviceSupport.java @@ -90,7 +90,6 @@ import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_ public class CasioGBX100DeviceSupport extends Casio2C2DSupport implements SharedPreferences.OnSharedPreferenceChangeListener { private static final Logger LOG = LoggerFactory.getLogger(CasioGBX100DeviceSupport.class); - private boolean mGetConfigurationPending = false; private boolean mRingNotificationPending = false; private final ArrayList mSyncedNotificationIDs = new ArrayList<>(); @@ -99,6 +98,8 @@ public class CasioGBX100DeviceSupport extends Casio2C2DSupport implements Shared private final Handler mFindPhoneHandler = new Handler(); private final Handler mFakeRingDurationHandler = new Handler(); private final Handler mAutoRemoveMessageHandler = new Handler(); + private final Handler mReconnectHandler = new Handler(); + private boolean mNeedsGetConfiguration = false; public CasioGBX100DeviceSupport() { super(LOG); @@ -113,7 +114,7 @@ public class CasioGBX100DeviceSupport extends Casio2C2DSupport implements Shared protected TransactionBuilder initializeDevice(TransactionBuilder builder) { try { - new InitOperation(this, builder, mFirstConnect).perform(); + new InitOperation(this, builder, mFirstConnect, mNeedsGetConfiguration).perform(); } catch (IOException e) { GB.toast(getContext(), "Initializing Casio watch failed", Toast.LENGTH_SHORT, GB.ERROR, e); } @@ -538,6 +539,7 @@ public class CasioGBX100DeviceSupport extends Casio2C2DSupport implements Shared if(config == null) { try { mGetConfigurationPending = true; + mNeedsGetConfiguration = false; new GetConfigurationOperation(this, true).perform(); } catch (IOException e) { mGetConfigurationPending = false; @@ -621,4 +623,15 @@ public class CasioGBX100DeviceSupport extends Casio2C2DSupport implements Shared LOG.info("Error sending configuration change to watch"); } } + + public void reconnectDelayed() { + setAutoReconnect(true); + mNeedsGetConfiguration = true; + mReconnectHandler.postDelayed(new Runnable() { + @Override + public void run() { + connect(); + } + }, CasioConstants.CASIO_FAKE_RING_SLEEP_DURATION); + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/InitOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/InitOperation.java index f930cae1c..c0ffa2579 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/InitOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/InitOperation.java @@ -18,6 +18,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gbx100; import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGattCharacteristic; +import android.os.Handler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,13 +43,15 @@ public class InitOperation extends AbstractBTLEOperation