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

Amazfit Bip 3: Initial support

This commit is contained in:
José Rebelo 2024-03-17 13:06:31 +00:00
parent ae05f7fd42
commit ee6340c848
8 changed files with 424 additions and 2 deletions

View File

@ -0,0 +1,171 @@
/* Copyright (C) 2023-2024 Daniel Dakhno, José Rebelo
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 <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip3;
import android.content.Context;
import android.net.Uri;
import androidx.annotation.NonNull;
import java.util.regex.Pattern;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip3.AmazfitBip3Support;
public class AmazfitBip3Coordinator extends HuamiCoordinator {
@Override
protected Pattern getSupportedDeviceName() {
return Pattern.compile("^Amazfit Bip 3$", Pattern.CASE_INSENSITIVE);
}
@Override
public InstallHandler findInstallHandler(final Uri uri, final Context context) {
final AmazfitBip3FWInstallHandler handler = new AmazfitBip3FWInstallHandler(uri, context);
return handler.isValid() ? handler : null;
}
@Override
public int getBondingStyle() {
return BONDING_STYLE_REQUIRE_KEY;
}
@Override
public boolean supportsHeartRateMeasurement(final GBDevice device) {
return true;
}
@Override
public boolean supportsActivityTracks() {
return true;
}
@Override
public boolean supportsWeather() {
return true;
}
@Override
public boolean supportsMusicInfo() {
return true;
}
@Override
public int getWorldClocksSlotCount() {
return 20; // as enforced by Zepp
}
@Override
public int getWorldClocksLabelLength() {
return 30; // at least
}
@Override
public boolean supportsUnicodeEmojis() {
return true;
}
@Override
public boolean supportsStressMeasurement() {
return true;
}
@Override
public boolean supportsSpo2() {
return true;
}
@Override
public boolean supportsPai() {
return true;
}
public int[] getSupportedDeviceSpecificSettings(final GBDevice device) {
return new int[]{
R.xml.devicesettings_amazfitbip3pro,
R.xml.devicesettings_vibrationpatterns,
R.xml.devicesettings_wearlocation,
R.xml.devicesettings_heartrate_sleep_alert_activity_stress,
R.xml.devicesettings_goal_notification,
R.xml.devicesettings_timeformat,
R.xml.devicesettings_dateformat,
R.xml.devicesettings_world_clocks,
R.xml.devicesettings_liftwrist_display_sensitivity,
R.xml.devicesettings_inactivity_dnd,
R.xml.devicesettings_sync_calendar,
R.xml.devicesettings_reserve_reminders_calendar,
R.xml.devicesettings_expose_hr_thirdparty,
R.xml.devicesettings_bt_connected_advertisement,
R.xml.devicesettings_device_actions,
R.xml.devicesettings_high_mtu,
R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration
};
}
@Override
public String[] getSupportedLanguageSettings(GBDevice device) {
return new String[]{
"auto",
"cs_CZ",
"de_DE",
"el_GR",
"en_US",
"es_ES",
"fr_FR",
"id_ID",
"it_IT",
"ja_JP",
"ko_KO",
"nl_NL",
"pl_PL",
"pt_BR",
"ru_RU",
"th_TH",
"tr_TR",
"uk_UA",
"vi_VN",
"zh_CH",
"zh_TW",
};
}
@NonNull
@Override
public Class<? extends DeviceSupport> getDeviceSupportClass() {
return AmazfitBip3Support.class;
}
@Override
public int getDeviceNameResource() {
return R.string.devicetype_amazfit_bip3;
}
@Override
public int getDefaultIconResource() {
return R.drawable.ic_device_amazfit_bip;
}
@Override
public int getDisabledIconResource() {
return R.drawable.ic_device_amazfit_bip_disabled;
}
}

View File

@ -0,0 +1,39 @@
/* Copyright (C) 2024 José Rebelo
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 <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip3;
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.amazfitbip3.AmazfitBip3FirmwareInfo;
public class AmazfitBip3FWHelper extends HuamiFWHelper {
public AmazfitBip3FWHelper(final Uri uri, final Context context) throws IOException {
super(uri, context);
}
@Override
protected void determineFirmwareInfo(final byte[] wholeFirmwareBytes) {
firmwareInfo = new AmazfitBip3FirmwareInfo(wholeFirmwareBytes);
if (!firmwareInfo.isHeaderValid()) {
throw new IllegalArgumentException("Not an Amazfit Bip 3 firmware");
}
}
}

View File

@ -0,0 +1,49 @@
/* Copyright (C) 2024 José Rebelo
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 <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip3;
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 AmazfitBip3FWInstallHandler extends AbstractMiBandFWInstallHandler {
AmazfitBip3FWInstallHandler(final Uri uri, final Context context) {
super(uri, context);
}
@Override
protected String getFwUpgradeNotice() {
return mContext.getString(R.string.fw_upgrade_notice_amazfitbip3, helper.getHumanFirmwareVersion());
}
@Override
protected AbstractMiBandFWHelper createHelper(final Uri uri, final Context context) throws IOException {
return new AmazfitBip3FWHelper(uri, context);
}
@Override
protected boolean isSupportedDeviceType(final GBDevice device) {
return device.getType() == DeviceType.AMAZFITBIP3;
}
}

View File

@ -30,8 +30,6 @@ import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
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;
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip3pro.AmazfitBip3ProSupport;

View File

@ -61,6 +61,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitband5.AmazfitBa
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitband7.AmazfitBand7Coordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipLiteCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip3.AmazfitBip3Coordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip3pro.AmazfitBip3ProCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip5.AmazfitBip5Coordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbips.AmazfitBipSCoordinator;
@ -265,6 +266,7 @@ public enum DeviceType {
AMAZFITGTS4MINI(AmazfitGTS4MiniCoordinator.class),
AMAZFITTREX2(AmazfitTRex2Coordinator.class),
AMAZFITGTR3PRO(AmazfitGTR3ProCoordinator.class),
AMAZFITBIP3(AmazfitBip3Coordinator.class),
AMAZFITBIP3PRO(AmazfitBip3ProCoordinator.class),
AMAZFITCHEETAHPRO(AmazfitCheetahProCoordinator.class),
AMAZFITCHEETAHSQUARE(AmazfitCheetahSquareCoordinator.class),

View File

@ -0,0 +1,82 @@
/* Copyright (C) 2024 José Rebelo
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 <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip3;
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.service.devices.huami.miband4.MiBand4FirmwareInfo;
import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils;
public class AmazfitBip3FirmwareInfo extends HuamiFirmwareInfo {
private static final Map<Integer, String> crcToVersion = new HashMap<>();
static {
// firmware
// resources
// gps
}
public AmazfitBip3FirmwareInfo(final byte[] bytes) {
super(bytes);
}
@Override
protected HuamiFirmwareType determineFirmwareType(final byte[] bytes) {
if (ArrayUtils.equals(bytes, MiBand4FirmwareInfo.FW_HEADER, MiBand4FirmwareInfo.FW_HEADER_OFFSET)) {
if (searchString32BitAligned(bytes, "\0\0Amazfit Bip 3") && !searchString32BitAligned(bytes, "\0\0Amazfit Bip 3 Pro")) {
return HuamiFirmwareType.FIRMWARE;
}
return HuamiFirmwareType.INVALID;
}
if (ArrayUtils.startsWith(bytes, NEWRES_HEADER)) {
return HuamiFirmwareType.RES;
}
if (ArrayUtils.startsWith(bytes, UIHH_HEADER) && (bytes[4] == 1 || bytes[4] == 2)) {
return HuamiFirmwareType.WATCHFACE;
}
if (ArrayUtils.startsWith(bytes, AGPS_UIHH_HEADER)) {
return HuamiFirmwareType.AGPS_UIHH;
}
for (byte[] gpsHeader : GPS_HEADERS) {
if (ArrayUtils.startsWith(bytes, gpsHeader)) {
return HuamiFirmwareType.GPS;
}
}
return HuamiFirmwareType.INVALID;
}
@Override
public boolean isGenerallyCompatibleWith(final GBDevice device) {
return isHeaderValid() && device.getType() == DeviceType.AMAZFITBIP3;
}
@Override
protected Map<Integer, String> getCrcMap() {
return crcToVersion;
}
}

View File

@ -0,0 +1,79 @@
/* Copyright (C) 2024 José Rebelo
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 <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip3;
import android.content.Context;
import android.net.Uri;
import java.io.IOException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip3.AmazfitBip3FWHelper;
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.AmazfitBipSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.update.UpdateFirmwareOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.update.UpdateFirmwareOperation2020;
public class AmazfitBip3Support extends AmazfitBipSupport {
@Override
public byte getCryptFlags() {
return (byte) 0x80;
}
@Override
protected byte getAuthFlags() {
return 0x00;
}
@Override
protected boolean notificationHasExtraHeader() {
return true;
}
@Override
public boolean supportsSunriseSunsetWindHumidity() {
return true;
}
@Override
public HuamiFWHelper createFWHelper(final Uri uri, final Context context) throws IOException {
return new AmazfitBip3FWHelper(uri, context);
}
@Override
public UpdateFirmwareOperation createUpdateFirmwareOperation(final Uri uri) {
return new UpdateFirmwareOperation2020(uri, this);
}
@Override
public void onSetCallState(final CallSpec callSpec) {
onSetCallStateNew(callSpec);
}
@Override
public int getActivitySampleSize() {
return 8;
}
@Override
protected AmazfitBip3Support setDisplayItems(final TransactionBuilder builder) {
setDisplayItemsNew(builder, false, false, R.array.pref_gtsgtr2_display_items_default);
return this;
}
}

View File

@ -137,6 +137,7 @@
<string name="fw_upgrade_notice">You are about to install the %s.</string>
<string name="fw_upgrade_notice_amazfitbip">You are about to install the %s firmware on your Amazfit Bip.\n\nPlease make sure to install the .fw file, then the .res file, and finally the .gps file. Your watch will reboot after installing the .fw file.\n\nNote: You do not have to install .res and .gps if these files are exactly the same as the ones previously installed.\n\nPROCEED AT YOUR OWN RISK!</string>
<string name="fw_upgrade_notice_amazfitbip_lite">You are about to install the %s firmware on your Amazfit Bip Lite.\n\nPlease make sure to install the .fw file, and after that the .res file. Your watch 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_amazfitbip3">You are about to install the %s firmware on your Amazfit Bip 3.\n\nPlease make sure to install the .fw file, and after that the .res file. Your watch 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_amazfitbip3pro">You are about to install the %s firmware on your Amazfit Bip 3 Pro.\n\nPlease make sure to install the .fw file, and after that the .res file. Your watch 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_amazfitcor">You are about to install the %s firmware on your Amazfit Cor.\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_amazfitcor2">You are about to install the %s firmware on your Amazfit Cor 2.
@ -1441,6 +1442,7 @@
<string name="devicetype_amazfit_gts4_mini">Amazfit GTS 4 Mini</string>
<string name="devicetype_amazfit_gtr3">Amazfit GTR 3</string>
<string name="devicetype_amazfit_gtr3_pro">Amazfit GTR 3 Pro</string>
<string name="devicetype_amazfit_bip3">Amazfit Bip 3</string>
<string name="devicetype_amazfit_bip3_pro">Amazfit Bip 3 Pro</string>
<string name="devicetype_amazfit_bip5">Amazfit Bip 5</string>
<string name="devicetype_amazfit_gtr4">Amazfit GTR 4</string>