diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java index 8eb2a0511..c620f5124 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java @@ -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 diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java index ff920162f..0ace462f4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java @@ -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;