Casio: Disable connection priority change on connection

This commit is contained in:
José Rebelo
2026-05-12 22:03:13 +01:00
parent 4fb9bf6698
commit 4490fddb7e
5 changed files with 33 additions and 9 deletions
@@ -990,7 +990,9 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
if (connectionType.usesBluetoothClassic() || connectionType.usesBluetoothLE()) { if (connectionType.usesBluetoothClassic() || connectionType.usesBluetoothLE()) {
settings = ArrayUtils.insert(0, settings, R.xml.devicesettings_reconnect_periodic); settings = ArrayUtils.insert(0, settings, R.xml.devicesettings_reconnect_periodic);
settings = ArrayUtils.insert(0, settings, R.xml.devicesettings_device_connect_back); settings = ArrayUtils.insert(0, settings, R.xml.devicesettings_device_connect_back);
settings = ArrayUtils.add(settings, R.xml.devicesettings_connection_priority_low_power); if (supportsConnectionPriority()) {
settings = ArrayUtils.add(settings, R.xml.devicesettings_connection_priority_low_power);
}
} }
return settings; return settings;
@@ -1201,4 +1203,9 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
// 2 seconds. // 2 seconds.
return 2000; return 2000;
} }
@Override
public boolean supportsConnectionPriority() {
return true;
}
} }
@@ -965,4 +965,10 @@ public interface DeviceCoordinator {
* @return delay in ms for this device to wait before a reconnection attempt is made. * @return delay in ms for this device to wait before a reconnection attempt is made.
*/ */
int getReconnectionDelay(); int getReconnectionDelay();
/**
* Returns whether the device supports changing bluetooth connection priority.
* @return
*/
boolean supportsConnectionPriority();
} }
@@ -46,4 +46,9 @@ public abstract class CasioDeviceCoordinator extends AbstractBLEDeviceCoordinato
public DeviceKind getDeviceKind(@NonNull GBDevice device) { public DeviceKind getDeviceKind(@NonNull GBDevice device) {
return DeviceKind.WATCH; return DeviceKind.WATCH;
} }
@Override
public boolean supportsConnectionPriority() {
return false;
}
} }
@@ -458,10 +458,13 @@ public abstract class AbstractBTLEMultiDeviceSupport extends AbstractBTLEDeviceS
initializeDevice(builder, deviceIdx); initializeDevice(builder, deviceIdx);
boolean lowPower = getDevicePrefs().getConnectionPriorityLowPower(); if (getDevice().getDeviceCoordinator().supportsConnectionPriority()) {
// have to explicitly request normal ("balanced") as some Android devices remember the last final boolean lowPower = getDevicePrefs().getConnectionPriorityLowPower();
// request. Else low power would become a set once option. // have to explicitly request normal ("balanced") as some Android devices remember the last
builder.requestConnectionPriority(lowPower ? BluetoothGatt.CONNECTION_PRIORITY_LOW_POWER : BluetoothGatt.CONNECTION_PRIORITY_BALANCED); // request. Else low power would become a set once option.
// #5054 / #5956 - However, on some devices requesting it altogether can make the connection fail
builder.requestConnectionPriority(lowPower ? BluetoothGatt.CONNECTION_PRIORITY_LOW_POWER : BluetoothGatt.CONNECTION_PRIORITY_BALANCED);
}
builder.queue(); builder.queue();
} }
@@ -366,10 +366,13 @@ public abstract class AbstractBTLESingleDeviceSupport extends AbstractBTLEDevice
initializeDevice(builder); initializeDevice(builder);
boolean lowPower = getDevicePrefs().getConnectionPriorityLowPower(); if (getDevice().getDeviceCoordinator().supportsConnectionPriority()) {
// have to explicitly request normal ("balanced") as some Android devices remember the last final boolean lowPower = getDevicePrefs().getConnectionPriorityLowPower();
// request. Else low power would become a set once option. // have to explicitly request normal ("balanced") as some Android devices remember the last
builder.requestConnectionPriority(lowPower ? BluetoothGatt.CONNECTION_PRIORITY_LOW_POWER : BluetoothGatt.CONNECTION_PRIORITY_BALANCED); // request. Else low power would become a set once option.
// #5054 / #5956 - However, on some devices requesting it altogether can make the connection fail
builder.requestConnectionPriority(lowPower ? BluetoothGatt.CONNECTION_PRIORITY_LOW_POWER : BluetoothGatt.CONNECTION_PRIORITY_BALANCED);
}
builder.queue(); builder.queue();
} }