Bangle.js: Fix stack overflow on initialization

Fix regression introduced by 280f4fc61. We should never call
performInitialized in the initializeDevice function, as that can cause
race conditions or, in this case, a stack overflow due to the recursive
initialization.
This commit is contained in:
José Rebelo
2025-06-23 21:59:29 +01:00
parent a16d7a18fc
commit 9d4dca5d5b
@@ -369,7 +369,8 @@ public class BangleJSDeviceSupport extends AbstractBTLESingleDeviceSupport {
// https://codeberg.org/Freeyourgadget/Gadgetbridge/issues/2996 - sometimes we get
// initializeDevice called but no characteristics have been fetched - try and reconnect in that case
LOG.warn("RX/TX characteristics are null, will attempt to reconnect");
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.WAITING_FOR_RECONNECT, getContext()));
builder.setUpdateState(gbDevice, GBDevice.State.WAITING_FOR_RECONNECT, getContext());
return builder;
}
builder.setCallback(this);
builder.notify(rxCharacteristic, true);
@@ -397,7 +398,7 @@ public class BangleJSDeviceSupport extends AbstractBTLESingleDeviceSupport {
LOG.info("Initialization Done");
requestBangleGPSPowerStatus();
requestBangleGPSPowerStatus(builder);
return builder;
}
@@ -510,13 +511,17 @@ public class BangleJSDeviceSupport extends AbstractBTLESingleDeviceSupport {
private void uartTxJSON(String taskName, JSONObject json) {
try {
TransactionBuilder builder = performInitialized(taskName);
uartTx(builder, "\u0010GB("+jsonToString(json)+")\n");
uartTxJSON(builder, json);
builder.queue(getQueue());
} catch (IOException e) {
GB.toast(getContext(), "Error in "+taskName+": " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
}
}
private void uartTxJSON(TransactionBuilder builder, JSONObject json) {
uartTx(builder, "\u0010GB("+jsonToString(json)+")\n");
}
private void uartTxJSONError(String taskName, String message, String id) {
JSONObject o = new JSONObject();
try {
@@ -1277,12 +1282,12 @@ public class BangleJSDeviceSupport extends AbstractBTLESingleDeviceSupport {
uartTx(builder, cmd+"\n");
}
void requestBangleGPSPowerStatus() {
void requestBangleGPSPowerStatus(final TransactionBuilder builder) {
try {
JSONObject o = new JSONObject();
o.put("t", "is_gps_active");
LOG.debug("Requesting gps power status: " + o.toString());
uartTxJSON("is_gps_active", o);
LOG.debug("Requesting gps power status: {}", o);
uartTxJSON(builder, o);
} catch (JSONException e) {
GB.toast(getContext(), "uartTxJSONError: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
}