ble: add per-device setting to request BluetoothGatt.CONNECTION_PRIORITY_LOW_POWER

This commit is contained in:
Thomas Kuehne
2025-05-21 20:51:14 +02:00
committed by José Rebelo
parent 8c59fdbd5b
commit e9415f3350
8 changed files with 54 additions and 8 deletions
@@ -624,4 +624,5 @@ public class DeviceSettingsPreferenceConst {
public static final String PREF_DISPLAY_ENABLED_ALL_DAY = "display_all_day";
public static final String PREF_DISPLAY_ON_START = "display_on_start";
public static final String PREF_DISPLAY_ON_END = "display_on_end";
public static final String PREF_CONNECTION_PRIORITY_LOW_POWER = "connection_priority_low_power";
}
@@ -1,7 +1,7 @@
/* Copyright (C) 2015-2024 akasaka / Genjitsu Labs, Alicia Hormann, Andreas
/* Copyright (C) 2015-2025 akasaka / Genjitsu Labs, Alicia Hormann, Andreas
Shimokawa, Arjan Schrijver, Carsten Pfeiffer, Daniel Dakhno, Daniele Gobbetti,
Davis Mosenkovs, Dmitry Markin, José Rebelo, Matthieu Baerts, Nephiel,
Petr Vaněk, Taavi Eomäe, Johannes Krude
Petr Vaněk, Taavi Eomäe, Johannes Krude, Thomas Kuehne
This file is part of Gadgetbridge.
@@ -800,6 +800,10 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
settings = ArrayUtils.insert(0, settings, R.xml.devicesettings_reconnect_bl_classic);
}
if (connectionType.usesBluetoothLE() || connectionType.usesBluetoothClassic()){
settings = ArrayUtils.add(settings, R.xml.devicesettings_connection_priority_low_power);
}
return settings;
}
@@ -1,5 +1,6 @@
/* Copyright (C) 2015-2024 Andreas Böhler, Arjan Schrijver, Carsten Pfeiffer,
Daniel Dakhno, Daniele Gobbetti, Johannes Krude, JohnnySun, José Rebelo
/* Copyright (C) 2015-2025 Andreas Böhler, Arjan Schrijver, Carsten Pfeiffer,
Daniel Dakhno, Daniele Gobbetti, Johannes Krude, JohnnySun, José Rebelo,
Thomas Kuehne
This file is part of Gadgetbridge.
@@ -369,7 +370,14 @@ public abstract class AbstractBTLEDeviceSupport extends AbstractDeviceSupport im
bleApi.initializeDevice(builder);
}
initializeDevice(builder).queue(getQueue());
initializeDevice(builder);
boolean lowPower = getDevicePrefs().getConnectionPriorityLowPower();
// have to explicitly request normal ("balanced") as some Android devices remember the last
// request. Else low power would become a set once option.
builder.requestConnectionPriority(lowPower ? BluetoothGatt.CONNECTION_PRIORITY_LOW_POWER : BluetoothGatt.CONNECTION_PRIORITY_BALANCED);
builder.queue(getQueue());
}
@Override
@@ -454,7 +454,14 @@ public abstract class AbstractBTLEMultiDeviceSupport extends AbstractDeviceSuppo
bleApis[deviceIdx].initializeDevice(builder);
}
initializeDevice(builder, deviceIdx).queue(getQueue(deviceIdx));
initializeDevice(builder, deviceIdx);
boolean lowPower = getDevicePrefs().getConnectionPriorityLowPower();
// have to explicitly request normal ("balanced") as some Android devices remember the last
// request. Else low power would become a set once option.
builder.requestConnectionPriority(lowPower ? BluetoothGatt.CONNECTION_PRIORITY_LOW_POWER : BluetoothGatt.CONNECTION_PRIORITY_BALANCED);
builder.queue(getQueue(deviceIdx));
}
@Override
@@ -1,6 +1,6 @@
/* Copyright (C) 2016-2024 Andreas Shimokawa, Anemograph, Carsten Pfeiffer,
/* Copyright (C) 2016-2025 Andreas Shimokawa, Anemograph, Carsten Pfeiffer,
Daniel Dakhno, Daniele Gobbetti, Davis Mosenkovs, Dikay900, Felix Konstantin
Maurer, José Rebelo, Petr Vaněk, Johannes Krude
Maurer, José Rebelo, Petr Vaněk, Johannes Krude, Thomas Kuehne
This file is part of Gadgetbridge.
@@ -120,6 +120,10 @@ public class DevicePrefs extends Prefs {
return getBoolean(PREF_ALLOW_HIGH_MTU, true);
}
public boolean getConnectionPriorityLowPower() {
return getBoolean(PREF_CONNECTION_PRIORITY_LOW_POWER, false);
}
public DeviceCoordinator.ConnectionType getForcedConnectionTypeFromPrefs() {
final String connTypePref = getString(DeviceSettingsPreferenceConst.PREF_FORCE_CONNECTION_TYPE, "BOTH");
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="#7E7E7E">
<path
android:fillColor="@android:color/white"
android:pathData="M160,459Q160,530 207.5,581Q255,632 326,638L326,638L264,576L320,520L480,680L320,840L264,784L328,720L328,720Q223,714 151.5,639Q80,564 80,460Q80,351 155.5,275.5Q231,200 340,200L480,200L480,280L340,280Q265,280 212.5,332Q160,384 160,459ZM560,720L560,640L880,640L880,720L560,720ZM560,500L560,420L880,420L880,500L560,500ZM560,280L560,200L880,200L880,280L560,280Z"/>
</vector>
+2
View File
@@ -469,6 +469,8 @@
<string name="pref_summary_notifications_and_calls_title_reject">Off - ignore, On - reject</string>
<string name="prefs_notifications_and_calls_shake_reject">Shake wrist ignore/reject call</string>
<string name="pref_summary_notifications_and_calls_title_shake_reject">Duplicates watch button action</string>
<string name="connection_priority_low_power_title">Request low power</string>
<string name="connection_priority_low_power_summary">Reduce bluetooth priority and data rate connection parameters.</string>
<!-- Device Settings - Device Settings - Used in devicesettings_watchxplus.xml -->
<string name="pref_header_device_spec_settings">Device settings</string>
<string name="pref_title_device_spec_settings_force_time">Force synchronize time</string>
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreferenceCompat
android:icon="@drawable/ic_low_priority"
android:key="connection_priority_low_power"
android:layout="@layout/preference_checkbox"
android:title="@string/connection_priority_low_power_title"
android:summary="@string/connection_priority_low_power_summary"
android:defaultValue="false" />
</PreferenceScreen>