diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java index e637566b..cc85b678 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java @@ -1,5 +1,9 @@ package nodomain.freeyourgadget.gadgetbridge; +import nodomain.freeyourgadget.gadgetbridge.GBDevice.State; +import nodomain.freeyourgadget.gadgetbridge.miband.MiBandSupport; +import nodomain.freeyourgadget.gadgetbridge.pebble.PebbleIoThread; +import nodomain.freeyourgadget.gadgetbridge.pebble.PebbleSupport; import android.app.NotificationManager; import android.app.Service; import android.bluetooth.BluetoothAdapter; @@ -19,11 +23,6 @@ import android.support.v4.content.LocalBroadcastManager; import android.util.Log; import android.widget.Toast; -import nodomain.freeyourgadget.gadgetbridge.GBDevice.State; -import nodomain.freeyourgadget.gadgetbridge.miband.MiBandSupport; -import nodomain.freeyourgadget.gadgetbridge.pebble.PebbleIoThread; -import nodomain.freeyourgadget.gadgetbridge.pebble.PebbleSupport; - public class BluetoothCommunicationService extends Service { public static final String ACTION_START = "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.start"; @@ -110,6 +109,10 @@ public class BluetoothCommunicationService extends Service { if (!action.equals(ACTION_START) && !action.equals(ACTION_CONNECT)) { if (mDeviceSupport == null || (!isConnected() && !mDeviceSupport.useAutoConnect())) { // trying to send notification without valid Bluetooth connection + if (mGBDevice != null) { + // at least send back the current device state + mGBDevice.sendDeviceUpdateIntent(this); + } return START_STICKY; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/ControlCenter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/ControlCenter.java index 1767687b..dbaf303f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/ControlCenter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/ControlCenter.java @@ -57,6 +57,10 @@ public class ControlCenter extends Activity { } } refreshPairedDevices(); + + if (dev.isConnected() && dev.getFirmwareVersion() == null) { + requestDeviceInfo(); + } } } }; @@ -79,7 +83,6 @@ public class ControlCenter extends Activity { Intent startIntent = new Intent(ControlCenter.this, BluetoothCommunicationService.class); startIntent.setAction(BluetoothCommunicationService.ACTION_CONNECT); startIntent.putExtra("device_address", deviceList.get(position).getAddress()); - startService(startIntent); } } @@ -105,7 +108,17 @@ public class ControlCenter extends Activity { startIntent.setAction(BluetoothCommunicationService.ACTION_START); startService(startIntent); - Intent versionInfoIntent = new Intent(this, BluetoothCommunicationService.class); + requestDeviceInfo(); + } + + /** + * Requests information from the {@link BluetoothCommunicationService} about the connection state, + * firmware info, etc. + * + * Note that this method may cause an implicit device connection (for auto-connectable devices). + */ + private void requestDeviceInfo() { + Intent versionInfoIntent = new Intent(ControlCenter.this, BluetoothCommunicationService.class); versionInfoIntent.setAction(BluetoothCommunicationService.ACTION_REQUEST_VERSIONINFO); startService(versionInfoIntent); }