1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-04 01:09:47 +01:00

Basic Amazfit Neo support (#2117)

Merge branch 'amazfit_neo' of codeberg.org:xaos/Gadgetbridge into amazfit_neo

updated menu items and settings, also disabled music info

added some classes, strings, etc. for Amazfit Neo (shows up but does not connect)

Merge branch 'amazfit_neo' of codeberg.org:xaos/Gadgetbridge into amazfit_neo

Merge branch 'master' into amazfit_neo

updated menu items and settings, also disabled music info

Merge branch 'authkey_errmsg' into amazfit_neo

refined error message for invalid authentication keys

added some classes, strings, etc. for Amazfit Neo (shows up but does not connect)

Co-authored-by: xaos <xaos@xaos.tech>
Reviewed-on: https://codeberg.org/Freeyourgadget/Gadgetbridge/pulls/2117
Co-Authored-By: xaos <xaos@noreply.codeberg.org>
Co-Committed-By: xaos <xaos@noreply.codeberg.org>
This commit is contained in:
xaos 2021-01-20 16:03:58 +01:00 committed by Andreas Shimokawa
parent 203176a01e
commit 4d47d53a8f
12 changed files with 418 additions and 0 deletions

View File

@ -52,6 +52,8 @@ public class HuamiConst {
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 AMAZFIT_BAND5_NAME = "Amazfit Band 5";
public static final String AMAZFIT_NEO_NAME = "Amazfit Neo";
public static final String PREF_ACTIVATE_DISPLAY_ON_LIFT = "activate_display_on_lift_wrist";
public static final String PREF_DISPLAY_ON_LIFT_START = "display_on_lift_start";

View File

@ -0,0 +1,106 @@
/* Copyright (C) 2020 Andreas Shimokawa
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.amazfitneo;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.net.Uri;
import androidx.annotation.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
public class AmazfitNeoCoordinator extends HuamiCoordinator {
private static final Logger LOG = LoggerFactory.getLogger(AmazfitNeoCoordinator.class);
@Override
public DeviceType getDeviceType() {
return DeviceType.AMAZFITNEO;
}
@NonNull
@Override
public DeviceType getSupportedType(GBDeviceCandidate candidate) {
try {
BluetoothDevice device = candidate.getDevice();
String name = device.getName();
if (name != null && name.equalsIgnoreCase(HuamiConst.AMAZFIT_NEO_NAME)) {
return DeviceType.AMAZFITNEO;
}
} catch (Exception ex) {
LOG.error("unable to check device support", ex);
}
return DeviceType.UNKNOWN;
}
@Override
public InstallHandler findInstallHandler(Uri uri, Context context) {
AmazfitNeoFWInstallHandler handler = new AmazfitNeoFWInstallHandler(uri, context);
return handler.isValid() ? handler : 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_amazfitneo,
R.xml.devicesettings_wearlocation,
R.xml.devicesettings_timeformat,
R.xml.devicesettings_disconnectnotification,
R.xml.devicesettings_expose_hr_thirdparty,
R.xml.devicesettings_bt_connected_advertisement,
R.xml.devicesettings_device_actions,
R.xml.devicesettings_pairingkey,
R.xml.devicesettings_high_mtu
};
}
@Override
public int getBondingStyle() {
return BONDING_STYLE_REQUIRE_KEY;
}
}

View File

@ -0,0 +1,41 @@
/* Copyright (C) 2020 Andreas Shimokawa
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.amazfitneo;
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.amazfitneo.AmazfitNeoFirmwareInfo;
public class AmazfitNeoFWHelper extends HuamiFWHelper {
public AmazfitNeoFWHelper(Uri uri, Context context) throws IOException {
super(uri, context);
}
@Override
protected void determineFirmwareInfo(byte[] wholeFirmwareBytes) {
firmwareInfo = new AmazfitNeoFirmwareInfo(wholeFirmwareBytes);
if (!firmwareInfo.isHeaderValid()) {
throw new IllegalArgumentException("Not even a Amazfit Band 5 firmware and you really want Amazfit Neo firmware");
}
}
}

View File

@ -0,0 +1,50 @@
/* Copyright (C) 020 Andreas Shimokawa
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.amazfitneo;
import android.content.Context;
import android.net.Uri;
import java.io.IOException;
import nodomain.freeyourgadget.gadgetbridge.R;
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 AmazfitNeoFWInstallHandler extends AbstractMiBandFWInstallHandler {
AmazfitNeoFWInstallHandler(Uri uri, Context context) {
super(uri, context);
}
@Override
protected String getFwUpgradeNotice() {
return mContext.getString(R.string.fw_upgrade_notice_miband5, helper.getHumanFirmwareVersion());
}
@Override
protected AbstractMiBandFWHelper createHelper(Uri uri, Context context) throws IOException {
return new AmazfitNeoFWHelper(uri, context);
}
@Override
protected boolean isSupportedDeviceType(GBDevice device) {
return device.getType() == DeviceType.AMAZFITNEO;
}
}

View File

@ -55,6 +55,7 @@ public enum DeviceType {
AMAZFITBIPU(28, R.drawable.ic_device_amazfit_bip, R.drawable.ic_device_amazfit_bip_disabled, R.string.devicetype_amazfit_bipu),
AMAZFITVERGEL(29, R.drawable.ic_device_amazfit_bip, R.drawable.ic_device_amazfit_bip_disabled, R.string.devicetype_amazfit_vergel),
AMAZFITBIPUPRO(30, R.drawable.ic_device_amazfit_bip, R.drawable.ic_device_amazfit_bip_disabled, R.string.devicetype_amazfit_bipu),
AMAZFITNEO(31, R.drawable.ic_device_amazfit_bip, R.drawable.ic_device_amazfit_bip_disabled, R.string.devicetype_amazfit_neo),
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

@ -39,6 +39,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.CasioGBX100Dev
import nodomain.freeyourgadget.gadgetbridge.service.devices.hplus.HPlusSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitband5.AmazfitBand5Support;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitneo.AmazfitNeoSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.AmazfitBipLiteSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.AmazfitBipSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbips.AmazfitBipSLiteSupport;
@ -213,6 +214,9 @@ public class DeviceSupportFactory {
case AMAZFITBAND5:
deviceSupport = new ServiceDeviceSupport(new AmazfitBand5Support(), EnumSet.of(ServiceDeviceSupport.Flags.BUSY_CHECKING));
break;
case AMAZFITNEO:
deviceSupport = new ServiceDeviceSupport(new AmazfitNeoSupport(), EnumSet.of(ServiceDeviceSupport.Flags.BUSY_CHECKING));
break;
case VIBRATISSIMO:
deviceSupport = new ServiceDeviceSupport(new VibratissimoSupport(), EnumSet.of(ServiceDeviceSupport.Flags.THROTTLING, ServiceDeviceSupport.Flags.BUSY_CHECKING));
break;

View File

@ -0,0 +1,85 @@
/* Copyright (C) 2020 Andreas Shimokawa
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.amazfitneo;
import java.util.HashMap;
import java.util.Map;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareInfo;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareType;
import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils;
public class AmazfitNeoFirmwareInfo extends HuamiFirmwareInfo {
public static final byte[] FW_HEADER = new byte[]{
0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x9c, (byte) 0xe3, 0x7d, 0x5c, 0x00, 0x04
};
public static final int FW_HEADER_OFFSET = 16;
private static Map<Integer, String> crcToVersion = new HashMap<>();
static {
// no known fw so far
}
public AmazfitNeoFirmwareInfo(byte[] bytes) {
super(bytes);
}
@Override
protected HuamiFirmwareType determineFirmwareType(byte[] bytes) {
return HuamiFirmwareType.INVALID;
/*
if (ArrayUtils.equals(bytes, RES_HEADER, COMPRESSED_RES_HEADER_OFFSET) || ArrayUtils.equals(bytes, NEWRES_HEADER, COMPRESSED_RES_HEADER_OFFSET_NEW) || ArrayUtils.equals(bytes, NEWRES_HEADER, COMPRESSED_RES_HEADER_OFFSET)) {
return HuamiFirmwareType.RES_COMPRESSED;
}
if (ArrayUtils.equals(bytes, FW_HEADER, FW_HEADER_OFFSET)) {
if (searchString32BitAligned(bytes, "Amazfit Neo")) {
return HuamiFirmwareType.FIRMWARE;
}
return HuamiFirmwareType.INVALID;
}
if (ArrayUtils.startsWith(bytes, WATCHFACE_HEADER_UIHH)) {
return HuamiFirmwareType.WATCHFACE;
}
if (ArrayUtils.startsWith(bytes, NEWFT_HEADER)) {
if (bytes[10] == 0x03 || bytes[10] == 0x06) {
return HuamiFirmwareType.FONT;
}
}
// somebody might have unpacked the compressed res
if (ArrayUtils.startsWith(bytes, RES_HEADER)) {
return HuamiFirmwareType.RES;
}
return HuamiFirmwareType.INVALID;*/
}
@Override
public boolean isGenerallyCompatibleWith(GBDevice device) {
return isHeaderValid() && device.getType() == DeviceType.AMAZFITNEO;
}
@Override
protected Map<Integer, String> getCrcMap() {
return crcToVersion;
}
}

View File

@ -0,0 +1,52 @@
/* Copyright (C) 2020 Andreas Shimokawa
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.amazfitneo;
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.amazfitneo.AmazfitBand5FWHelper;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband5.MiBand5Support;
public class AmazfitNeoSupport extends MiBand5Support {
private static final Logger LOG = LoggerFactory.getLogger(AmazfitNeoSupport.class);
@Override
protected AmazfitNeoSupport setDisplayItems(TransactionBuilder builder) {
setDisplayItemsNew(builder, false, R.array.pref_neo_display_items_default);
return this;
}
//@Override
//protected AmazfitNeoSupport setShortcuts(TransactionBuilder builder) {
// setDisplayItemsNew(builder, true, R.array.pref_amazfitband5_shortcuts_default);
// return this;
//}
//@Override
//public HuamiFWHelper createFWHelper(Uri uri, Context context) throws IOException {
// return new AmazfitBand5FWHelper(uri, context);
//}
}

View File

@ -53,6 +53,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.hplus.MakibesF68Coordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.Q8Coordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.SG2Coordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitband5.AmazfitBand5Coordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitneo.AmazfitNeoCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipLiteCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbips.AmazfitBipSCoordinator;
@ -241,6 +242,7 @@ public class DeviceHelper {
result.add(new AmazfitBipUCoordinator());
result.add(new AmazfitBipUProCoordinator());
result.add(new AmazfitBand5Coordinator());
result.add(new AmazfitNeoCoordinator());
result.add(new MiBand3Coordinator());
result.add(new MiBand4Coordinator());
result.add(new MiBand5Coordinator());

View File

@ -408,6 +408,42 @@
<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>
<item>@string/menuitem_hr</item>
<item>@string/menuitem_weather</item>
<item>@string/menuitem_stopwatch</item>
<item>@string/menuitem_alarm</item>
<item>@string/menuitem_worldclock</item>
<item>@string/menuitem_activity</item>
<item>@string/menuitem_goal</item>
</string-array>
<string-array name="pref_neo_display_items_values">
<item>@string/p_menuitem_pai</item>
<item>@string/p_menuitem_dnd</item>
<item>@string/p_menuitem_hr</item>
<item>@string/p_menuitem_weather</item>
<item>@string/p_menuitem_stopwatch</item>
<item>@string/p_menuitem_alarm</item>
<item>@string/p_menuitem_worldclock</item>
<item>@string/p_menuitem_activity</item>
<item>@string/p_menuitem_goal</item>
</string-array>
<string-array name="pref_neo_display_items_default">
<item>@string/p_menuitem_pai</item>
<item>@string/p_menuitem_dnd</item>
<item>@string/p_menuitem_hr</item>
<item>@string/p_menuitem_weather</item>
<item>@string/p_menuitem_stopwatch</item>
<item>@string/p_menuitem_alarm</item>
<item>@string/p_menuitem_worldclock</item>
<item>@string/p_menuitem_activity</item>
<item>@string/p_menuitem_goal</item>
</string-array>
<string-array name="pref_amazfitband5_display_items">
<item>@string/menuitem_status</item>
<item>@string/menuitem_pai</item>

View File

@ -791,6 +791,7 @@
<string name="devicetype_miband4">Mi Band 4</string>
<string name="devicetype_miband5">Mi Band 5</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>
<string name="devicetype_amazfit_bip_lite">Amazfit Bip Lite</string>
<string name="devicetype_amazfit_cor">Amazfit Cor</string>

View File

@ -0,0 +1,38 @@
<?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:icon="@drawable/ic_widgets"
android:defaultValue="@array/pref_neo_display_items_default"
android:dialogTitle="@string/mi2_prefs_display_items"
android:entries="@array/pref_neo_display_items"
android:entryValues="@array/pref_neo_display_items_values"
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_amazfitband5_shortcuts_default"
android:dialogTitle="@string/bip_prefs_shortcuts"
android:entries="@array/pref_amazfitband5_shortcuts"
android:entryValues="@array/pref_amazfitband5_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>
<!--
android:entryValues="@array/pref_amazfitband5_display_items_values"
-->