mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-29 05:16:51 +01:00
Various changes related to INITIALZED device state
Due to a bug in DeviceCommunicationService.isConnected(), devices using the INITIALIZED state only worked when they had useAutoConnect set to true (Mi Band) Now setting devices to INITIALIZED state to allow any action send to DeviceCommunicationService is mandatory. As an exception only REQUEST_VERSIONINFO will be also be allowed for CONNECTED state. This also fixes a problem when notifications came in on the Pebble with 3.x FW before we actually knew it was FW 3.x (INITZALIZED state on the Pebble now implies that we know the FW version)
This commit is contained in:
parent
ce7b42d9d4
commit
6125594703
@ -24,7 +24,6 @@ import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice.State;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
@ -82,7 +81,7 @@ public class DeviceCommunicationService extends Service {
|
||||
GBDevice device = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
||||
if (mGBDevice.equals(device)) {
|
||||
mGBDevice = device;
|
||||
boolean enableReceivers = mDeviceSupport != null && (mDeviceSupport.useAutoConnect() || mGBDevice.isConnected());
|
||||
boolean enableReceivers = mDeviceSupport != null && (mDeviceSupport.useAutoConnect() || mGBDevice.isInitialized());
|
||||
GB.setReceiversEnableState(enableReceivers, context);
|
||||
GB.updateNotification(mGBDevice.getName() + " " + mGBDevice.getStateString(), context);
|
||||
} else {
|
||||
@ -124,7 +123,7 @@ public class DeviceCommunicationService extends Service {
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
|
||||
if (mDeviceSupport == null || (!isConnected() && !mDeviceSupport.useAutoConnect())) {
|
||||
if ((mDeviceSupport == null) || (!(isConnected() && action.equals(ACTION_REQUEST_VERSIONINFO)) && !isInitialized() && !mDeviceSupport.useAutoConnect())) {
|
||||
// trying to send notification without valid Bluetooth connection
|
||||
if (mGBDevice != null) {
|
||||
// at least send back the current device state
|
||||
@ -275,11 +274,15 @@ public class DeviceCommunicationService extends Service {
|
||||
}
|
||||
|
||||
private boolean isConnected() {
|
||||
return mGBDevice != null && mGBDevice.getState() == State.CONNECTED;
|
||||
return mGBDevice != null && mGBDevice.isConnected();
|
||||
}
|
||||
|
||||
private boolean isConnecting() {
|
||||
return mGBDevice != null && mGBDevice.getState() == State.CONNECTING;
|
||||
return mGBDevice != null && mGBDevice.isConnecting();
|
||||
}
|
||||
|
||||
private boolean isInitialized() {
|
||||
return mGBDevice != null && mGBDevice.isInitialized();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,16 +19,16 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PBWReader;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleInstallable;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.bt.GBDeviceIoThread;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppInfo;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppManagementResult;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PBWReader;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleInstallable;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.bt.GBDeviceIoThread;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.bt.GBDeviceProtocol;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
|
||||
public class PebbleIoThread extends GBDeviceIoThread {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PebbleIoThread.class);
|
||||
@ -89,7 +89,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
gbDevice.sendDeviceUpdateIntent(getContext());
|
||||
|
||||
mIsConnected = true;
|
||||
|
||||
write(mPebbleProtocol.encodeFirmwareVersionReq());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -280,6 +280,8 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
LOG.info("syncing time");
|
||||
write(mPebbleProtocol.encodeSetTime(-1));
|
||||
}
|
||||
gbDevice.setState(GBDevice.State.INITIALIZED);
|
||||
gbDevice.sendDeviceUpdateIntent(getContext());
|
||||
return false;
|
||||
case APP_MANAGEMENT_RES:
|
||||
GBDeviceEventAppManagementResult appMgmtRes = (GBDeviceEventAppManagementResult) deviceEvent;
|
||||
|
Loading…
Reference in New Issue
Block a user