1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-24 10:56:50 +01:00

Mi Band 4: Make high MTU support optional

Fixes #1766
This commit is contained in:
Andreas Shimokawa 2020-02-04 10:04:01 +01:00
parent 68e746edff
commit 3226d61ecd
5 changed files with 26 additions and 7 deletions

View File

@ -22,4 +22,5 @@ public class DeviceSettingsPreferenceConst {
public static final String PREF_WEARLOCATION = "wearlocation";
public static final String PREF_SCREEN_ORIENTATION = "screen_orientation";
public static final String PREF_RESERVER_ALARMS_CALENDAR = "reserve_alarms_calendar";
public static final String PREF_ALLOW_HIGH_MTU = "allow_high_mtu";
}

View File

@ -97,7 +97,8 @@ public class MiBand4Coordinator extends HuamiCoordinator {
R.xml.devicesettings_liftwrist_display,
R.xml.devicesettings_swipeunlock,
R.xml.devicesettings_expose_hr_thirdparty,
R.xml.devicesettings_pairingkey
R.xml.devicesettings_pairingkey,
R.xml.devicesettings_high_mtu
};
}

View File

@ -25,7 +25,6 @@ import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.text.format.DateFormat;
import android.widget.Toast;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@ -55,7 +54,6 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.Logging;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
@ -136,6 +134,11 @@ import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
import nodomain.freeyourgadget.gadgetbridge.util.Version;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_ALLOW_HIGH_MTU;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DATEFORMAT;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_RESERVER_ALARMS_CALENDAR;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_TIMEFORMAT;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_WEARLOCATION;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.DEFAULT_VALUE_VIBRATION_COUNT;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.DEFAULT_VALUE_VIBRATION_PROFILE;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_COUNT;
@ -1250,6 +1253,10 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
case HuamiDeviceEvent.MTU_REQUEST:
int mtu = (value[2] & 0xff) << 8 | value[1] & 0xff;
LOG.info("device announced MTU of " + mtu);
Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()));
if (!prefs.getBoolean(PREF_ALLOW_HIGH_MTU, false)) {
break;
}
mMTU = mtu;
/*
* not really sure if this would make sense, is this event already a proof of a successful MTU
@ -1673,7 +1680,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
BluetoothGattCharacteristic characteristic = getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION);
Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()));
int availableSlots = prefs.getInt(DeviceSettingsPreferenceConst.PREF_RESERVER_ALARMS_CALENDAR, 0);
int availableSlots = prefs.getInt(PREF_RESERVER_ALARMS_CALENDAR, 0);
if (availableSlots > 0) {
CalendarEvents upcomingEvents = new CalendarEvents();
@ -1747,10 +1754,10 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
case MiBandConst.PREF_SWIPE_UNLOCK:
setBandScreenUnlock(builder);
break;
case DeviceSettingsPreferenceConst.PREF_TIMEFORMAT:
case PREF_TIMEFORMAT:
setTimeFormat(builder);
break;
case DeviceSettingsPreferenceConst.PREF_DATEFORMAT:
case PREF_DATEFORMAT:
setDateFormat(builder);
break;
case HuamiConst.PREF_LANGUAGE:
@ -1759,7 +1766,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
case HuamiConst.PREF_EXPOSE_HR_THIRDPARTY:
setExposeHRThridParty(builder);
break;
case DeviceSettingsPreferenceConst.PREF_WEARLOCATION:
case PREF_WEARLOCATION:
setWearLocation(builder);
break;
}

View File

@ -180,6 +180,8 @@
<string name="pref_title_expose_hr">3rd party realtime HR access</string>
<string name="pref_title_use_custom_font">Use custom font</string>
<string name="pref_summary_use_custom_font">Enable this if your device has a custom font firmware for emoji support</string>
<string name="pref_title_allow_high_mtu">Allow high MTU</string>
<string name="pref_summary_allow_high_mtu">Will increase transfer speed, but might not work with some Android devices</string>
<string name="pref_display_add_device_fab">Connect new device button</string>
<string name="pref_display_add_device_fab_on">Always visible</string>
<string name="pref_display_add_device_fab_off">Visible only if no device is added</string>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreference
android:defaultValue="false"
android:key="allow_high_mtu"
android:summary="@string/pref_summary_allow_high_mtu"
android:title="@string/pref_title_allow_high_mtu" />
</androidx.preference.PreferenceScreen>