Set device change reason for all state changes

Apply f0d4efcb9 to all remaining devices.
This commit is contained in:
José Rebelo
2025-03-30 19:25:44 +01:00
parent f0d4efcb94
commit c7fa48594a
19 changed files with 36 additions and 33 deletions
@@ -275,7 +275,7 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
}
void handleDeviceConnect(GBDevice device){
if(!device.getDeviceCoordinator().isConnectable()){
if (!device.getDeviceCoordinator().isConnectable()){
device.setState(GBDevice.State.WAITING_FOR_SCAN);
device.sendDeviceUpdateIntent(GBApplication.getContext(), GBDevice.DeviceUpdateSubject.CONNECTION_STATE);
return;
@@ -424,7 +424,7 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
}
gbDevice.setState(updateDeviceState.state);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
}
protected void handleGBDeviceEvent(GBDeviceEventFmFrequency frequencyEvent) {
@@ -402,6 +402,11 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
String action = intent.getAction();
if(GBDevice.ACTION_DEVICE_CHANGED.equals(action)){
GBDevice device = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
if (device == null) {
// Should never happen
LOG.error("Got ACTION_DEVICE_CHANGED without device");
return;
}
// create a new instance of the changed devices coordinator, in case it's capabilities changed
DeviceStruct cachedStruct = getDeviceStructOrNull(device);
@@ -414,13 +419,13 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
GBDevice.DeviceUpdateSubject subject = (GBDevice.DeviceUpdateSubject) intent.getSerializableExtra(GBDevice.EXTRA_UPDATE_SUBJECT);
if(subject == GBDevice.DeviceUpdateSubject.DEVICE_STATE && device.isInitialized()){
if (subject == GBDevice.DeviceUpdateSubject.DEVICE_STATE && device.isInitialized()) {
sendDeviceConnectedBroadcast(device.getAddress());
sendCachedNotifications(device);
}else if(subject == GBDevice.DeviceUpdateSubject.DEVICE_STATE && (device.getState() == GBDevice.State.SCANNED)){
} else if(subject == GBDevice.DeviceUpdateSubject.DEVICE_STATE && (device.getState() == GBDevice.State.SCANNED)) {
sendDeviceAPIBroadcast(device.getAddress(), API_LEGACY_ACTION_DEVICE_SCANNED);
}
}else if(BLEScanService.EVENT_DEVICE_FOUND.equals(action)){
} else if(BLEScanService.EVENT_DEVICE_FOUND.equals(action)){
String deviceAddress = intent.getStringExtra(BLEScanService.EXTRA_DEVICE_ADDRESS);
GBDevice target = GBApplication
@@ -201,7 +201,7 @@ public abstract class BtClassicIoThread extends GBDeviceIoThread {
protected void setUpdateState(GBDevice.State state) {
gbDevice.setState(state);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
}
/**
@@ -337,7 +337,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
}
gbDevice.setState(GBDevice.State.INITIALIZING);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
rxCharacteristic = getCharacteristic(BangleJSConstants.UUID_CHARACTERISTIC_NORDIC_UART_RX);
txCharacteristic = getCharacteristic(BangleJSConstants.UUID_CHARACTERISTIC_NORDIC_UART_TX);
@@ -51,7 +51,7 @@ public abstract class CasioSupport extends AbstractBTLEDeviceSupport {
public void setInitialized() {
mFirstConnect = false;
gbDevice.setState(GBDevice.State.INITIALIZED);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
}
@Override
@@ -295,13 +295,13 @@ public class CasioGB6900DeviceSupport extends CasioSupport {
mHandlerThread = new CasioGB6900HandlerThread(getDevice(), getContext(), this);
mHandlerThread.start();
gbDevice.setState(GBDevice.State.INITIALIZED);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
handled = true;
break;
default:
LOG.warn("handleInitResponse: Error initializing device, received unexpected value: " + data);
gbDevice.setState(GBDevice.State.NOT_CONNECTED);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
handled = true;
break;
}
@@ -97,9 +97,7 @@ public class G1DeviceSupport extends AbstractBTLEDeviceSupport {
scheduleBatteryPolling();
// Device is ready for use.
builder.add(
new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
gbDevice.sendDeviceUpdateIntent(getContext());
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
return builder;
}
@@ -571,7 +571,7 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
enableBatteryLevelUpdate();
gbDevice.setState(GBDevice.State.INITIALIZED);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
sendOutgoingMessage("request supported file types", new SupportedFileTypesMessage());
@@ -89,7 +89,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
LOG.info("Initializing");
gbDevice.setState(GBDevice.State.INITIALIZING);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
measureCharacteristic = getCharacteristic(HPlusConstants.UUID_CHARACTERISTIC_MEASURE);
ctrlCharacteristic = getCharacteristic(HPlusConstants.UUID_CHARACTERISTIC_CONTROL);
@@ -102,7 +102,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
sendUserInfo(builder); //Sync preferences
gbDevice.setState(GBDevice.State.INITIALIZED);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
if (syncHelper == null) {
syncHelper = new HPlusHandlerThread(getDevice(), getContext(), this);
@@ -103,7 +103,7 @@ public class BFH16DeviceSupport extends AbstractBTLEDeviceSupport {
LOG.info("Initializing BFH16");
gbDevice.setState(GBDevice.State.INITIALIZING);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
measureCharacteristic = getCharacteristic(BFH16Constants.BFH16_SERVICE1_NOTIFY);
ctrlCharacteristic = getCharacteristic(BFH16Constants.BFH16_SERVICE1_WRITE);
@@ -114,7 +114,7 @@ public class BFH16DeviceSupport extends AbstractBTLEDeviceSupport {
syncSettings(builder);
gbDevice.setState(GBDevice.State.INITIALIZED);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
LOG.info("Initialization BFH16 Done");
@@ -64,7 +64,7 @@ public class JYouSupport extends AbstractBTLEDeviceSupport {
logger.info("Initializing");
gbDevice.setState(GBDevice.State.INITIALIZING);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
BluetoothGattCharacteristic measureCharacteristic = getCharacteristic(JYouConstants.UUID_CHARACTERISTIC_MEASURE);
ctrlCharacteristic = getCharacteristic(JYouConstants.UUID_CHARACTERISTIC_CONTROL);
@@ -75,7 +75,7 @@ public class JYouSupport extends AbstractBTLEDeviceSupport {
syncSettings(builder);
gbDevice.setState(GBDevice.State.INITIALIZED);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
logger.info("Initialization Done");
@@ -805,7 +805,7 @@ public class LefunDeviceSupport extends AbstractBTLEDeviceSupport {
*/
public void completeInitialization() {
gbDevice.setState(GBDevice.State.INITIALIZED);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
onReadConfiguration("");
}
@@ -489,7 +489,7 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement
GB.updateTransferNotification(null, getContext().getString(R.string.busy_task_fetch_activity_data), true, 0, getContext());
gbDevice.setState(GBDevice.State.INITIALIZING);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
this.mControlCharacteristic = getCharacteristic(MakibesHR3Constants.UUID_CHARACTERISTIC_CONTROL);
this.mReportCharacteristic = getCharacteristic(MakibesHR3Constants.UUID_CHARACTERISTIC_REPORT);
@@ -507,7 +507,7 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement
this.requestFitness(builder);
gbDevice.setState(GBDevice.State.INITIALIZED);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
getDevice().setFirmwareVersion("N/A");
getDevice().setFirmwareVersion2("N/A");
@@ -92,7 +92,7 @@ public class MarstekB2500DeviceSupport extends AbstractBTLEDeviceSupport {
if (!is_initialized) {
sendCommand("set time (initial)", encodeSetCurrentTime());
gbDevice.setState(GBDevice.State.INITIALIZED);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
is_initialized = true;
}
return true;
@@ -78,7 +78,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
LOG.info("Initializing");
gbDevice.setState(GBDevice.State.INITIALIZING);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
measureCharacteristic = getCharacteristic(No1F1Constants.UUID_CHARACTERISTIC_MEASURE);
ctrlCharacteristic = getCharacteristic(No1F1Constants.UUID_CHARACTERISTIC_CONTROL);
@@ -93,7 +93,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
builder.write(ctrlCharacteristic, new byte[]{No1F1Constants.CMD_BATTERY});
gbDevice.setState(GBDevice.State.INITIALIZED);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
LOG.info("Initialization Done");
@@ -173,7 +173,7 @@ class PebbleIoThread extends GBDeviceIoThread {
String deviceAddress = gbDevice.getAddress();
GBDevice.State originalState = gbDevice.getState();
gbDevice.setState(GBDevice.State.CONNECTING);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
try {
// contains only one ":"? then it is addr:port
int firstColon = deviceAddress.indexOf(":");
@@ -225,7 +225,7 @@ class PebbleIoThread extends GBDeviceIoThread {
} catch (IOException e) {
LOG.warn("error while connecting: " + e.getMessage(), e);
gbDevice.setState(originalState);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
mInStream = null;
mOutStream = null;
@@ -238,7 +238,7 @@ class PebbleIoThread extends GBDeviceIoThread {
mIsConnected = true;
write(mPebbleProtocol.encodeFirmwareVersionReq());
gbDevice.setState(GBDevice.State.CONNECTED);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
return true;
}
@@ -249,7 +249,7 @@ class PebbleIoThread extends GBDeviceIoThread {
if (!mIsConnected) {
if (GBApplication.getPrefs().getAutoReconnect(getDevice()) && !mQuit) {
gbDevice.setState(GBDevice.State.WAITING_FOR_RECONNECT);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
}
return;
}
@@ -110,7 +110,7 @@ public class SonySWR12DeviceSupport extends AbstractBTLEDeviceSupport {
gbDevice.setFirmwareVersion("N/A");
gbDevice.setFirmwareVersion2("N/A");
gbDevice.setState(GBDevice.State.INITIALIZED);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
}
}
@@ -71,7 +71,7 @@ public class WaspOSDeviceSupport extends AbstractBTLEDeviceSupport {
LOG.info("Initializing");
gbDevice.setState(GBDevice.State.INITIALIZING);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
rxCharacteristic = getCharacteristic(WaspOSConstants.UUID_CHARACTERISTIC_NORDIC_UART_RX);
txCharacteristic = getCharacteristic(WaspOSConstants.UUID_CHARACTERISTIC_NORDIC_UART_TX);
@@ -88,7 +88,7 @@ public class WaspOSDeviceSupport extends AbstractBTLEDeviceSupport {
// get version
gbDevice.setState(GBDevice.State.INITIALIZED);
gbDevice.sendDeviceUpdateIntent(getContext());
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
LOG.info("Initialization Done");