1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-08 14:18:08 +02:00

WIP initial Miband 6 support (#2277)

Reviewed-on: https://codeberg.org/Freeyourgadget/Gadgetbridge/pulls/2277
Co-authored-by: jhey <jhey@noreply.codeberg.org>
Co-committed-by: jhey <jhey@noreply.codeberg.org>
This commit is contained in:
jhey 2021-05-09 22:52:36 +02:00 committed by Andreas Shimokawa
parent a1005ae479
commit 58d3eaaa9f
12 changed files with 458 additions and 0 deletions

View File

@ -51,6 +51,7 @@ public class HuamiConst {
public static final String MI_BAND3_NAME_2 = "Xiaomi Band 3";
public static final String MI_BAND4_NAME = "Mi Smart Band 4";
public static final String MI_BAND5_NAME = "Mi Smart Band 5";
public static final String MI_BAND6_NAME = "Mi Smart Band 6";
public static final String AMAZFIT_BAND5_NAME = "Amazfit Band 5";
public static final String AMAZFIT_NEO_NAME = "Amazfit Neo";
public static final String AMAZFIT_X = "Amazfit X";

View File

@ -0,0 +1,92 @@
package nodomain.freeyourgadget.gadgetbridge.devices.huami.miband6;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.net.Uri;
import androidx.annotation.NonNull;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband5.MiBand5Coordinator;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.R;
public class MiBand6Coordinator extends HuamiCoordinator {
private static final Logger LOG = LoggerFactory.getLogger(MiBand6Coordinator.class);
@NonNull
@Override
public DeviceType getSupportedType(GBDeviceCandidate candidate) {
try {
BluetoothDevice device = candidate.getDevice();
String name = device.getName();
if (name != null && name.equalsIgnoreCase(HuamiConst.MI_BAND6_NAME)) {
return DeviceType.MIBAND6;
}
} catch (Exception ex) {
LOG.error("unable to check device support", ex);
}
return DeviceType.UNKNOWN;
}
@Override
public DeviceType getDeviceType() {
return DeviceType.MIBAND6;
}
@Override
public InstallHandler findInstallHandler(Uri uri, Context context) {
// TODO!
return null;
}
@Override
public boolean supportsHeartRateMeasurement(GBDevice device) {
return true;
}
@Override
public boolean supportsWeather() {
return true;
}
@Override
public boolean supportsActivityTracks() {
return true;
}
@Override
public boolean supportsMusicInfo() {
return true;
}
@Override
public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
return new int[]{
R.xml.devicesettings_miband6,
R.xml.devicesettings_wearlocation,
R.xml.devicesettings_custom_emoji_font,
R.xml.devicesettings_timeformat,
R.xml.devicesettings_dateformat,
R.xml.devicesettings_nightmode,
R.xml.devicesettings_liftwrist_display,
R.xml.devicesettings_swipeunlock,
R.xml.devicesettings_sync_calendar,
R.xml.devicesettings_expose_hr_thirdparty,
R.xml.devicesettings_pairingkey,
R.xml.devicesettings_high_mtu
};
}
@Override
public int getBondingStyle() {
return BONDING_STYLE_REQUIRE_KEY;
}
}

View File

@ -0,0 +1,37 @@
/* Copyright (C) 2017-2021 Andreas Shimokawa, Carsten Pfeiffer, odavo32nof
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.huami.miband6;
import android.content.Context;
import android.net.Uri;
import java.io.IOException;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband5.MiBand5FirmwareInfo;
public class MiBand6FWHelper extends HuamiFWHelper {
public MiBand6FWHelper(Uri uri, Context context) throws IOException {
super(uri, context);
}
@Override
protected void determineFirmwareInfo(byte[] wholeFirmwareBytes) {
throw new IllegalArgumentException("Not implemented.");
}
}

View File

@ -0,0 +1,50 @@
/* Copyright (C) 2015-2021 Andreas Shimokawa, Carsten Pfeiffer, odavo32nof
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.huami.miband6;
import android.content.Context;
import android.net.Uri;
import java.io.IOException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband5.MiBand5FWHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.AbstractMiBandFWHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.AbstractMiBandFWInstallHandler;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
class MiBand6FWInstallHandler extends AbstractMiBandFWInstallHandler {
MiBand6FWInstallHandler(Uri uri, Context context) {
super(uri, context);
}
@Override
protected String getFwUpgradeNotice() {
return mContext.getString(R.string.fw_upgrade_notice_miband6, helper.getHumanFirmwareVersion());
}
@Override
protected AbstractMiBandFWHelper createHelper(Uri uri, Context context) throws IOException {
return new MiBand6FWHelper(uri, context);
}
@Override
protected boolean isSupportedDeviceType(GBDevice device) {
return device.getType() == DeviceType.MIBAND6;
}
}

View File

@ -61,6 +61,7 @@ public enum DeviceType {
AMAZFITGTR2E(34, R.drawable.ic_device_zetime, R.drawable.ic_device_zetime_disabled, R.string.devicetype_amazfit_gtr2e),
AMAZFITGTS2E(35, R.drawable.ic_device_amazfit_bip, R.drawable.ic_device_amazfit_bip_disabled,R.string .devicetype_amazfit_gts2e),
AMAZFITX(36, R.drawable.ic_device_miband2, R.drawable.ic_device_miband2_disabled, R.string.devicetype_amazfit_x),
MIBAND6(37, R.drawable.ic_device_miband2, R.drawable.ic_device_miband2_disabled, R.string.devicetype_miband6),
HPLUS(40, R.drawable.ic_device_hplus, R.drawable.ic_device_hplus_disabled, R.string.devicetype_hplus),
MAKIBESF68(41, R.drawable.ic_device_hplus, R.drawable.ic_device_hplus_disabled, R.string.devicetype_makibes_f68),
EXRIZUK8(42, R.drawable.ic_device_hplus, R.drawable.ic_device_hplus_disabled, R.string.devicetype_exrizu_k8),

View File

@ -62,6 +62,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitx.Amazf
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband3.MiBand3Support;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband4.MiBand4Support;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband5.MiBand5Support;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband6.MiBand6Support;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppe.ZeppESupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.id115.ID115Support;
import nodomain.freeyourgadget.gadgetbridge.service.devices.itag.ITagSupport;
@ -173,6 +174,9 @@ public class DeviceSupportFactory {
case MIBAND5:
deviceSupport = new ServiceDeviceSupport(new MiBand5Support(), EnumSet.of(ServiceDeviceSupport.Flags.BUSY_CHECKING));
break;
case MIBAND6:
deviceSupport = new ServiceDeviceSupport(new MiBand6Support(), EnumSet.of(ServiceDeviceSupport.Flags.BUSY_CHECKING));
break;
case AMAZFITBIP:
deviceSupport = new ServiceDeviceSupport(new AmazfitBipSupport(), EnumSet.of(ServiceDeviceSupport.Flags.BUSY_CHECKING));
break;

View File

@ -0,0 +1,51 @@
/* Copyright (C) 2017-2021 Andreas Shimokawa, Cristian Alfano, Daniele
Gobbetti, odavo32nof
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband6;
import java.util.HashMap;
import java.util.Map;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareInfo;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareType;
public class MiBand6FirmwareInfo extends HuamiFirmwareInfo {
private static final Map<Integer, String> crcToVersion = new HashMap<>();
public MiBand6FirmwareInfo(byte[] bytes) {
super(bytes);
}
@Override
protected HuamiFirmwareType determineFirmwareType(byte[] bytes) {
return HuamiFirmwareType.INVALID;
}
@Override
public boolean isGenerallyCompatibleWith(GBDevice device) {
// return isHeaderValid() && device.getType() == DeviceType.MIBAND5;
return false;
}
@Override
protected Map<Integer, String> getCrcMap() {
return crcToVersion;
}
}

View File

@ -0,0 +1,64 @@
/* Copyright (C) 2019-2021 Andreas Shimokawa, Manuel Ruß, odavo32nof
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband6;
import android.content.Context;
import android.net.Uri;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband5.MiBand5FWHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband6.MiBand6FWHelper;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband5.MiBand5Support;
public class MiBand6Support extends MiBand5Support {
private static final Logger LOG = LoggerFactory.getLogger(MiBand6Support.class);
@Override
protected MiBand6Support setDisplayItems(TransactionBuilder builder) {
setDisplayItemsNew(builder, false, true, R.array.pref_miband6_display_items_default);
return this;
}
@Override
protected MiBand6Support setShortcuts(TransactionBuilder builder) {
setDisplayItemsNew(builder, true, true, R.array.pref_miband6_shortcuts_default);
return this;
}
@Override
public HuamiFWHelper createFWHelper(Uri uri, Context context) throws IOException {
return new MiBand6FWHelper(uri, context);
}
@Override
public boolean supportsSunriseSunsetWindHumidity() {
return true;
}
@Override
public int getActivitySampleSize() {
return 8;
}
}

View File

@ -68,6 +68,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgtr.AmazfitGTRC
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgtr.AmazfitGTRLiteCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgtr2.AmazfitGTR2Coordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitx.AmazfitXCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband6.MiBand6Coordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.zeppe.ZeppECoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgtr2.AmazfitGTR2eCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgts.AmazfitGTSCoordinator;
@ -260,6 +261,7 @@ public class DeviceHelper {
result.add(new MiBand3Coordinator());
result.add(new MiBand4Coordinator());
result.add(new MiBand5Coordinator());
result.add(new MiBand6Coordinator());
result.add(new MiBand2HRXCoordinator());
result.add(new MiBand2Coordinator()); // Note: MiBand2 and all of the above must come before MiBand because detection is hacky, atm
result.add(new MiBandCoordinator());

View File

@ -408,6 +408,130 @@
<item>@string/p_menuitem_music</item>
</string-array>
<string-array name="pref_miband6_display_items">
<item>@string/menuitem_status</item>
<item>@string/menuitem_hr</item>
<item>@string/menuitem_workout</item>
<item>@string/menuitem_weather</item>
<item>@string/menuitem_notifications</item>
<item>@string/menuitem_alarm</item>
<item>@string/menuitem_takephoto</item>
<item>@string/menuitem_music</item>
<item>@string/menuitem_stopwatch</item>
<item>@string/menuitem_timer</item>
<item>@string/menuitem_findphone</item>
<item>@string/menuitem_mutephone</item>
<item>@string/menuitem_settings</item>
<item>@string/menuitem_activity</item>
<item>@string/menuitem_eventreminder</item>
<item>@string/menuitem_pai</item>
<item>@string/menuitem_worldclock</item>
<item>@string/menuitem_stress</item>
<item>@string/menuitem_cycles</item>
<item>@string/menuitem_spo2</item>
<item>@string/menuitem_breathing</item>
</string-array>
<string-array name="pref_miband6_display_items_values">
<item>@string/p_menuitem_status</item>
<item>@string/p_menuitem_hr</item>
<item>@string/p_menuitem_workout</item>
<item>@string/p_menuitem_weather</item>
<item>@string/p_menuitem_notifications</item>
<item>@string/p_menuitem_alarm</item>
<item>@string/p_menuitem_takephoto</item>
<item>@string/p_menuitem_music</item>
<item>@string/p_menuitem_stopwatch</item>
<item>@string/p_menuitem_timer</item>
<item>@string/p_menuitem_findphone</item>
<item>@string/p_menuitem_mutephone</item>
<item>@string/p_menuitem_settings</item>
<item>@string/p_menuitem_activity</item>
<item>@string/p_menuitem_eventreminder</item>
<item>@string/p_menuitem_pai</item>
<item>@string/p_menuitem_worldclock</item>
<item>@string/p_menuitem_stress</item>
<item>@string/p_menuitem_cycles</item>
<item>@string/p_menuitem_spo2</item>
<item>@string/p_menuitem_breathing</item>
</string-array>
<string-array name="pref_miband6_display_items_default">
<item>@string/menuitem_status</item>
<item>@string/menuitem_hr</item>
<item>@string/menuitem_workout</item>
<item>@string/menuitem_weather</item>
<item>@string/menuitem_notifications</item>
<item>@string/menuitem_alarm</item>
<item>@string/menuitem_takephoto</item>
<item>@string/menuitem_music</item>
<item>@string/menuitem_stopwatch</item>
<item>@string/menuitem_timer</item>
<item>@string/menuitem_findphone</item>
<item>@string/menuitem_mutephone</item>
<item>@string/menuitem_settings</item>
<item>@string/menuitem_activity</item>
<item>@string/menuitem_eventreminder</item>
<item>@string/menuitem_pai</item>
<item>@string/menuitem_worldclock</item>
<item>@string/menuitem_stress</item>
<item>@string/menuitem_cycles</item>
<item>@string/menuitem_spo2</item>
<item>@string/menuitem_breathing</item>
</string-array>
<string-array name="pref_miband6_shortcuts">
<item>@string/menuitem_status</item>
<item>@string/menuitem_hr</item>
<item>@string/menuitem_workout</item>
<item>@string/menuitem_weather</item>
<item>@string/menuitem_notifications</item>
<item>@string/menuitem_dnd</item>
<item>@string/menuitem_alarm</item>
<item>@string/menuitem_takephoto</item>
<item>@string/menuitem_music</item>
<item>@string/menuitem_stopwatch</item>
<item>@string/menuitem_timer</item>
<item>@string/menuitem_findphone</item>
<item>@string/menuitem_mutephone</item>
<item>@string/menuitem_eventreminder</item>
<item>@string/menuitem_pai</item>
<item>@string/menuitem_worldclock</item>
<item>@string/menuitem_stress</item>
<item>@string/menuitem_cycles</item>
<item>@string/menuitem_spo2</item>
<item>@string/menuitem_breathing</item>
</string-array>
<string-array name="pref_miband6_shortcuts_values">
<item>@string/p_menuitem_status</item>
<item>@string/p_menuitem_hr</item>
<item>@string/p_menuitem_workout</item>
<item>@string/p_menuitem_weather</item>
<item>@string/p_menuitem_notifications</item>
<item>@string/p_menuitem_dnd</item>
<item>@string/p_menuitem_alarm</item>
<item>@string/p_menuitem_takephoto</item>
<item>@string/p_menuitem_music</item>
<item>@string/p_menuitem_stopwatch</item>
<item>@string/p_menuitem_timer</item>
<item>@string/p_menuitem_findphone</item>
<item>@string/p_menuitem_mutephone</item>
<item>@string/p_menuitem_eventreminder</item>
<item>@string/p_menuitem_pai</item>
<item>@string/p_menuitem_worldclock</item>
<item>@string/p_menuitem_stress</item>
<item>@string/p_menuitem_cycles</item>
<item>@string/p_menuitem_spo2</item>
<item>@string/p_menuitem_breathing</item>
</string-array>
<string-array name="pref_miband6_shortcuts_default">
<item>@string/p_menuitem_notifications</item>
<item>@string/p_menuitem_weather</item>
<item>@string/p_menuitem_music</item>
</string-array>
<string-array name="pref_neo_display_items">
<item>@string/menuitem_pai</item>
<item>@string/menuitem_dnd</item>

View File

@ -85,6 +85,7 @@
<string name="fw_upgrade_notice_miband3">You are about to install the %s firmware on your Mi Band 3.\n\nPlease make sure to install the .fw file, and after that the .res file. Your band will reboot after installing the .fw file.\n\nNote: You do not have to install .res if it is exactly the same as the one previously installed.\n\nPROCEED AT YOUR OWN RISK!</string>
<string name="fw_upgrade_notice_miband4">You are about to install the %s firmware on your Mi Band 4.\n\nPlease make sure to install the .fw file, and after that the .res file. Your band will reboot after installing the .fw file.\n\nNote: You do not have to install .res if it is exactly the same as the one previously installed.\n\nPROCEED AT YOUR OWN RISK!</string>
<string name="fw_upgrade_notice_miband5">You are about to install the %s firmware on your Mi Band 5.\n\nPlease make sure to install the .fw file, and after that the .res file. Your band will reboot after installing the .fw file.\n\nNote: You do not have to install .res if it is exactly the same as the one previously installed.\n\nPROCEED AT YOUR OWN RISK!</string>
<string name="fw_upgrade_notice_miband6">You are about to install the %s firmware on your Mi Band 6.\n\nPlease make sure to install the .fw file, and after that the .res file. Your band will reboot after installing the .fw file.\n\nNote: You do not have to install .res if it is exactly the same as the one previously installed.\n\nPROCEED AT YOUR OWN RISK!</string>
<string name="fw_upgrade_notice_amazfitx">You are about to install the %s firmware on your Amazfit X.\n\nPlease make sure to install the .fw file, and after that the .res file. Your band will reboot after installing the .fw file.\n\nNote: You do not have to install .res if it is exactly the same as the one previously installed.\n\nPROCEED AT YOUR OWN RISK!</string>
<string name="fw_upgrade_notice_amazfitneo">You are about to install the %s firmware on your Amazfit Neo.
\n
@ -811,6 +812,7 @@
<string name="devicetype_miband3">Mi Band 3</string>
<string name="devicetype_miband4">Mi Band 4</string>
<string name="devicetype_miband5">Mi Band 5</string>
<string name="devicetype_miband6">Mi Band 6</string>
<string name="devicetype_amazfit_band5">Amazfit Band 5</string>
<string name="devicetype_amazfit_neo">Amazfit Neo</string>
<string name="devicetype_amazfit_bip">Amazfit Bip</string>

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.mobeta.android.dslv.DragSortListPreference
android:defaultValue="@array/pref_miband6_display_items_default"
android:dialogTitle="@string/mi2_prefs_display_items"
android:entries="@array/pref_miband6_display_items"
android:entryValues="@array/pref_miband6_display_items_values"
android:icon="@drawable/ic_widgets"
android:key="display_items_sortable"
android:persistent="true"
android:summary="@string/mi2_prefs_display_items_summary"
android:title="@string/mi2_prefs_display_items" />
<com.mobeta.android.dslv.DragSortListPreference
android:defaultValue="@array/pref_miband6_shortcuts_default"
android:dialogTitle="@string/bip_prefs_shortcuts"
android:entries="@array/pref_miband6_shortcuts"
android:entryValues="@array/pref_miband6_shortcuts_values"
android:key="shortcuts_sortable"
android:persistent="true"
android:summary="@string/bip_prefs_shotcuts_summary"
android:title="@string/bip_prefs_shortcuts" />
<ListPreference
android:icon="@drawable/ic_language"
android:defaultValue="auto"
android:entries="@array/pref_miband5_language"
android:entryValues="@array/pref_miband5_language_values"
android:key="language"
android:summary="%s"
android:title="@string/pref_title_language" />
</androidx.preference.PreferenceScreen>