mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-29 05:16:51 +01:00
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.
This commit is contained in:
parent
f659e34efc
commit
d0229847e7
@ -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.
|
||||
* <p/>
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,8 +28,6 @@ public interface EventHandler {
|
||||
|
||||
void onSetMusicInfo(String artist, String album, String track);
|
||||
|
||||
void onFirmwareVersionReq();
|
||||
|
||||
void onBatteryInfoReq();
|
||||
|
||||
void onInstallApp(Uri uri);
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
|
@ -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")) {
|
||||
|
@ -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();
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user