From d0229847e7d1e5c49092ae8a520d6450374fa485 Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Fri, 14 Aug 2015 23:37:47 +0200 Subject: [PATCH] onFirmwareVersionReq() is no more - version information is now provided implicitly by device initialization - ACTION_REQUEST_VERSIONINFO is now ACTION_REQUEST_DEVICEINFO and it will return the current device state of the service without asking any DeviceSupport instance. - ACTION_CONNECT now implicitly answers with a device update intent if it IS already connected. --- .../activities/ControlCenter.java | 10 +++---- .../activities/FwAppInstallerActivity.java | 13 +++++----- .../gadgetbridge/devices/EventHandler.java | 2 -- .../gadgetbridge/impl/GBDevice.java | 6 +++++ .../service/DeviceCommunicationService.java | 12 ++++----- .../service/ServiceDeviceSupport.java | 8 ------ .../service/bt/AbstractBTDeviceSupport.java | 6 ----- .../service/devices/miband/MiBandSupport.java | 26 ++++++++----------- 8 files changed, 33 insertions(+), 50 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java index e627db53..17ced04c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java @@ -82,11 +82,6 @@ public class ControlCenter extends Activity { refreshPairedDevices(); refreshBusyState(dev); - - if (dev.isInitialized() && dev.getFirmwareVersion() == null) { - LOG.info("device initalized, requesting more info"); - requestDeviceInfo(); - } break; } } @@ -163,11 +158,12 @@ public class ControlCenter extends Activity { * Requests information from the {@link DeviceCommunicationService} about the connection state, * firmware info, etc. *

- * Note that this method may cause an implicit device connection (for auto-connectable devices). + * Note that this will not need a connection to the device -- only the cached information + * from the service will be reported. */ private void requestDeviceInfo() { Intent versionInfoIntent = new Intent(ControlCenter.this, DeviceCommunicationService.class); - versionInfoIntent.setAction(DeviceCommunicationService.ACTION_REQUEST_VERSIONINFO); + versionInfoIntent.setAction(DeviceCommunicationService.ACTION_REQUEST_DEVICEINFO); startService(versionInfoIntent); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java index d4e64ea5..f214340c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java @@ -48,6 +48,7 @@ public class FwAppInstallerActivity extends Activity implements InstallActivity device = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE); if (device != null) { if (!device.isConnected()) { + setInstallEnabled(false); if (mayConnect) { GB.toast(FwAppInstallerActivity.this, getString(R.string.connecting), Toast.LENGTH_SHORT, GB.INFO); connect(); @@ -90,6 +91,7 @@ public class FwAppInstallerActivity extends Activity implements InstallActivity mayConnect = true; fwAppInstallTextView = (TextView) findViewById(R.id.debugTextView); installButton = (Button) findViewById(R.id.installButton); + setInstallEnabled(false); IntentFilter filter = new IntentFilter(); filter.addAction(ControlCenter.ACTION_QUIT); filter.addAction(GBDevice.ACTION_DEVICE_CHANGED); @@ -98,6 +100,7 @@ public class FwAppInstallerActivity extends Activity implements InstallActivity installButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + setInstallEnabled(false); installHandler.onStartInstall(); Intent startIntent = new Intent(FwAppInstallerActivity.this, DeviceCommunicationService.class); startIntent.setAction(DeviceCommunicationService.ACTION_INSTALL); @@ -110,19 +113,17 @@ public class FwAppInstallerActivity extends Activity implements InstallActivity installHandler = findInstallHandlerFor(uri); if (installHandler == null) { setInfoText(getString(R.string.installer_activity_unable_to_find_handler)); - setInstallEnabled(false); } else { setInfoText(getString(R.string.installer_activity_wait_while_determining_status)); - setInstallEnabled(false); // needed to get the device if (device == null || !device.isConnected()) { connect(); + } else { + Intent deviceInfoIntent = new Intent(this, DeviceCommunicationService.class); + deviceInfoIntent.setAction(DeviceCommunicationService.ACTION_REQUEST_DEVICEINFO); + startService(deviceInfoIntent); } - - Intent versionInfoIntent = new Intent(this, DeviceCommunicationService.class); - versionInfoIntent.setAction(DeviceCommunicationService.ACTION_REQUEST_VERSIONINFO); - startService(versionInfoIntent); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/EventHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/EventHandler.java index 4ed5f3d7..e3b6ada0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/EventHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/EventHandler.java @@ -28,8 +28,6 @@ public interface EventHandler { void onSetMusicInfo(String artist, String album, String track); - void onFirmwareVersionReq(); - void onBatteryInfoReq(); void onInstallApp(Uri uri); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java index ab050878..3bfdf9bf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java @@ -303,6 +303,12 @@ public class GBDevice implements Parcelable { CONNECTING, CONNECTED, INITIALIZING, + /** + * Means that the device is connected AND all the necessary initialization steps + * have been performed. At the very least, this means that basic information like + * device name, firmware version, hardware revision (as applicable) is available + * in the GBDevice. + */ INITIALIZED } } 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 66865a5d..a5d8ee9c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java @@ -45,8 +45,8 @@ public class DeviceCommunicationService extends Service { = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.settime"; public static final String ACTION_SETMUSICINFO = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.setmusicinfo"; - public static final String ACTION_REQUEST_VERSIONINFO - = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.request_versioninfo"; + public static final String ACTION_REQUEST_DEVICEINFO + = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.request_deviceinfo"; public static final String ACTION_REQUEST_APPINFO = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.request_appinfo"; public static final String ACTION_REQUEST_SCREENSHOT @@ -170,13 +170,13 @@ public class DeviceCommunicationService extends Service { mDeviceSupport = null; mGBDevice = null; } + } else if (mGBDevice != null) { + // send an update at least + mGBDevice.sendDeviceUpdateIntent(this); } break; - case ACTION_REQUEST_VERSIONINFO: + case ACTION_REQUEST_DEVICEINFO: mGBDevice.sendDeviceUpdateIntent(this); - if (mGBDevice.getFirmwareVersion() == null) { - mDeviceSupport.onFirmwareVersionReq(); - } break; case ACTION_NOTIFICATION_GENERIC: { String title = intent.getStringExtra("notification_title"); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java index 1ed66a5e..6be392b9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java @@ -144,14 +144,6 @@ public class ServiceDeviceSupport implements DeviceSupport { delegate.onSetMusicInfo(artist, album, track); } - @Override - public void onFirmwareVersionReq() { - if (checkBusy("firmware version request")) { - return; - } - delegate.onFirmwareVersionReq(); - } - @Override public void onBatteryInfoReq() { if (checkBusy("battery info request")) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/bt/AbstractBTDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/bt/AbstractBTDeviceSupport.java index 080781f1..266f3e7c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/bt/AbstractBTDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/bt/AbstractBTDeviceSupport.java @@ -147,12 +147,6 @@ public abstract class AbstractBTDeviceSupport extends AbstractDeviceSupport { sendToDevice(bytes); } - @Override - public void onFirmwareVersionReq() { - byte[] bytes = gbDeviceProtocol.encodeFirmwareVersionReq(); - sendToDevice(bytes); - } - @Override public void onBatteryInfoReq() { byte[] bytes = gbDeviceProtocol.encodeBatteryInfoReq(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java index 0d12ee3e..7da6aef6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java @@ -113,6 +113,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { .enableNotifications(builder, true) .setCurrentTime(builder) .requestBatteryInfo(builder) + .requestDeviceInfo(builder) .setInitialized(builder); return builder; @@ -264,6 +265,15 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { return this; } + private MiBandSupport requestDeviceInfo(TransactionBuilder builder) { + LOG.debug("Requesting Device Info!"); + BluetoothGattCharacteristic deviceInfo = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_DEVICE_INFO); + builder.read(deviceInfo); + BluetoothGattCharacteristic deviceName = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_DEVICE_NAME); + builder.read(deviceName); + return this; + } + /** * Part of device initialization process. Do not call manually. * @@ -495,20 +505,6 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { // not supported } - @Override - public void onFirmwareVersionReq() { - try { - TransactionBuilder builder = performInitialized("Get MI Band device info"); - BluetoothGattCharacteristic device_info = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_DEVICE_INFO); - builder.read(device_info); - BluetoothGattCharacteristic device_name = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_DEVICE_NAME); - builder.read(device_name); - builder.queue(getQueue()); - } catch (IOException ex) { - LOG.error("Unable to read device info from MI", ex); - } - } - @Override public void onBatteryInfoReq() { try { @@ -750,7 +746,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { default: for (byte b : value) { - LOG.warn("DATA: " + String.format("0x%2x", b)); + LOG.warn("DATA: " + String.format("0x%2x", b)); } } }