Xiaomi: allow forcing the connection type from connection settings

This commit is contained in:
MrYoranimo 2023-12-15 23:31:16 +01:00 committed by José Rebelo
parent 2812ad1429
commit 399248e22c
6 changed files with 66 additions and 0 deletions

View File

@ -427,4 +427,5 @@ public class DeviceSettingsPreferenceConst {
public static final String PREF_DEVICE_ACTION_START_NON_WEAR_BROADCAST = "prefs_events_forwarding_startnonwear_broadcast";
public static final String PREF_CLAP_HANDS_TO_WAKEUP_DEVICE = "pref_key_clap_hands_to_wakeup_device";
public static final String PREF_POWER_SAVING = "pref_key_power_saving";
public static final String PREF_FORCE_CONNECTION_TYPE = "pref_force_connection_type";
}

View File

@ -355,6 +355,20 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator {
return true;
}
@Override
public int[] getSupportedDeviceSpecificConnectionSettings() {
final List<Integer> settings = new ArrayList<>();
if (getConnectionType().equals(ConnectionType.BOTH)) {
settings.add(R.xml.devicesettings_force_connection_type);
}
return ArrayUtils.addAll(
super.getSupportedDeviceSpecificConnectionSettings(),
ArrayUtils.toPrimitive(settings.toArray(new Integer[0]))
);
}
@Override
public int[] getSupportedDeviceSpecificSettings(final GBDevice device) {
final List<Integer> settings = new ArrayList<>();

View File

@ -17,6 +17,8 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_FORCE_CONNECTION_TYPE;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.location.Location;
@ -39,6 +41,7 @@ import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.xiaomi.XiaomiCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.xiaomi.XiaomiFWHelper;
@ -115,9 +118,27 @@ public class XiaomiSupport extends AbstractDeviceSupport {
return false;
}
private DeviceCoordinator.ConnectionType getForcedConnectionTypeFromPrefs() {
final String connTypeAuto = getContext().getString(R.string.pref_force_connection_type_auto_value);
String connTypePref = getDevicePrefs().getString(PREF_FORCE_CONNECTION_TYPE, connTypeAuto);
if (getContext().getString(R.string.pref_force_connection_type_ble_value).equals(connTypePref))
return DeviceCoordinator.ConnectionType.BLE;
if (getContext().getString(R.string.pref_force_connection_type_bt_classic_value).equals(connTypePref))
return DeviceCoordinator.ConnectionType.BT_CLASSIC;
// either set to default, unknown option selected, or has not been set
return DeviceCoordinator.ConnectionType.BOTH;
}
private XiaomiConnectionSupport createConnectionSpecificSupport() {
DeviceCoordinator.ConnectionType connType = getCoordinator().getConnectionType();
if (connType == DeviceCoordinator.ConnectionType.BOTH) {
connType = getForcedConnectionTypeFromPrefs();
}
switch (connType) {
case BLE:
case BOTH:

View File

@ -3581,4 +3581,14 @@
<item>ignore</item>
</string-array>
<string-array name="pref_force_connection_type">
<item>@string/pref_force_connection_type_auto</item>
<item>@string/pref_force_connection_type_ble</item>
<item>@string/pref_force_connection_type_bt_classic</item>
</string-array>
<string-array name="pref_force_connection_type_values">
<item>@string/pref_force_connection_type_auto_value</item>
<item>@string/pref_force_connection_type_ble_value</item>
<item>@string/pref_force_connection_type_bt_classic_value</item>
</string-array>
</resources>

View File

@ -2579,4 +2579,12 @@
<string name="uploadwatchfaceoperation_in_progress">Uploading watchface</string>
<string name="uploadwatchfaceoperation_complete">Watchface installation completed</string>
<string name="uploadwatchfaceoperation_failed">Watchface installation failed</string>
<string name="pref_force_connection_type_title">Force connection type</string>
<string name="pref_force_connection_type_description">You may try forcing the connection type in case your device does not respond to Gadgetbridge</string>
<string name="pref_force_connection_type_auto">Automatic</string>
<string name="pref_force_connection_type_ble">Bluetooth LE</string>
<string name="pref_force_connection_type_bt_classic">Bluetooth Classic</string>
<string name="pref_force_connection_type_auto_value" translatable="false">BOTH</string>
<string name="pref_force_connection_type_ble_value" translatable="false">BLE</string>
<string name="pref_force_connection_type_bt_classic_value" translatable="false">BT_CLASSIC</string>
</resources>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference
android:key="pref_force_connection_type"
android:icon="@drawable/ic_bluetooth"
android:title="@string/pref_force_connection_type_title"
android:summary="@string/pref_force_connection_type_description"
android:entries="@array/pref_force_connection_type"
android:entryValues="@array/pref_force_connection_type_values"
android:defaultValue="@string/pref_force_connection_type_auto_value"
/>
</PreferenceScreen>