mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
Fix first connect on the Casio GBX100/GBD-200 series
This commit is contained in:
parent
a3f3bb212a
commit
3dd2869283
@ -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<Integer> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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<CasioGBX100DeviceSuppor
|
||||
private final TransactionBuilder builder;
|
||||
private final CasioGBX100DeviceSupport support;
|
||||
private final boolean mFirstConnect;
|
||||
private final boolean mNeedsGetConfiguration;
|
||||
private boolean mWriteAllFeaturesInitPending = false;
|
||||
|
||||
public InitOperation(CasioGBX100DeviceSupport support, TransactionBuilder builder, boolean firstConnect) {
|
||||
public InitOperation(CasioGBX100DeviceSupport support, TransactionBuilder builder, boolean firstConnect, boolean needsGetConfiguration) {
|
||||
super(support);
|
||||
this.builder = builder;
|
||||
this.support = support;
|
||||
this.mFirstConnect = firstConnect;
|
||||
this.mNeedsGetConfiguration = needsGetConfiguration;
|
||||
LOG.info("mFirstConnect: " + mFirstConnect);
|
||||
builder.setCallback(this);
|
||||
}
|
||||
@ -348,22 +351,21 @@ public class InitOperation extends AbstractBTLEOperation<CasioGBX100DeviceSuppor
|
||||
LOG.error("Error setting device to initialized: " + e.getMessage());
|
||||
}
|
||||
} else if(data[1] == 0x01) {
|
||||
// The writeAllFeaturesInit request triggers encryption (again). However, the transaction
|
||||
// never completes. Instead, the watch reports with 0x3d and we abort the current
|
||||
// transaction.
|
||||
// This write is only required for the first connect, for later reconnections,
|
||||
// it's not required and the watch does not respond with 0x3d. Thus, we set
|
||||
// it directly to initialized.
|
||||
if(mFirstConnect)
|
||||
writeAllFeaturesInit();
|
||||
else
|
||||
support.setInitialized();
|
||||
support.setInitialized();
|
||||
}
|
||||
} else if(data[0] == 0x3d) {
|
||||
LOG.info("Init operation done.");
|
||||
// Finally, we set the state to initialized here!
|
||||
// If it's the first connection attempt, disconnect the watch and
|
||||
// reconnect delayed. This is required on Android 13 since it's no longer
|
||||
// possible to cancel a dangling write request.
|
||||
// Upon first reconnection, a "getConfiguration" request is required. On further
|
||||
// reconnections, we just sync the profile.
|
||||
support.setInitialized();
|
||||
if(mFirstConnect) {
|
||||
support.disconnect();
|
||||
support.reconnectDelayed();
|
||||
} else if(mNeedsGetConfiguration) {
|
||||
support.onReadConfiguration(null);
|
||||
} else {
|
||||
// on first connect, this is called by onReadConfiguration
|
||||
|
Loading…
Reference in New Issue
Block a user