1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-01 06:22:55 +01:00

Zepp OS: Match devices by exact bluetooth name

This attemts to reduce false positives, especially for devices that
present as two bluetooth devices such as the GTR 4.
This commit is contained in:
José Rebelo 2024-02-01 18:45:45 +00:00
parent 34fd18885a
commit aa4a7912ef
20 changed files with 10 additions and 123 deletions

View File

@ -24,7 +24,6 @@ import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.zeppos.ZeppOsCoordinator;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
public class AmazfitActiveCoordinator extends ZeppOsCoordinator {
@Override
@ -42,12 +41,6 @@ public class AmazfitActiveCoordinator extends ZeppOsCoordinator {
return R.string.devicetype_amazfit_active;
}
@Override
public boolean supports(final GBDeviceCandidate candidate) {
final String name = candidate.getName();
return name.startsWith(HuamiConst.AMAZFIT_ACTIVE_NAME) && !name.contains("Edge");
}
@Override
public boolean supportsContinuousFindDevice() {
return true;

View File

@ -19,7 +19,6 @@ package nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitactiveedge;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
@ -47,11 +46,6 @@ public class AmazfitActiveEdgeCoordinator extends ZeppOsCoordinator {
return R.string.devicetype_amazfit_active_edge;
}
@Override
protected Pattern getSupportedDeviceName() {
return Pattern.compile(HuamiConst.AMAZFIT_ACTIVE_EDGE_NAME + ".*");
}
@Override
public boolean supportsContinuousFindDevice() {
return true;

View File

@ -19,7 +19,6 @@ package nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbalance;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
@ -42,12 +41,6 @@ public class AmazfitBalanceCoordinator extends ZeppOsCoordinator {
return R.string.devicetype_amazfit_balance;
}
@Override
protected Pattern getSupportedDeviceName() {
return Pattern.compile(HuamiConst.AMAZFIT_BALANCE_NAME + ".*");
}
@Override
public boolean supportsContinuousFindDevice() {
return true;

View File

@ -19,7 +19,6 @@ package nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitband7;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
@ -37,11 +36,6 @@ public class AmazfitBand7Coordinator extends ZeppOsCoordinator {
return new HashSet<>(Arrays.asList(252, 253, 254));
}
@Override
protected Pattern getSupportedDeviceName() {
return Pattern.compile(HuamiConst.AMAZFIT_BAND7_NAME + ".*", Pattern.CASE_INSENSITIVE);
}
@Override
public boolean supportsAgpsUpdates() {
return false;

View File

@ -19,7 +19,6 @@ package nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip5;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
@ -37,11 +36,6 @@ public class AmazfitBip5Coordinator extends ZeppOsCoordinator {
return new HashSet<>(Arrays.asList(8454400, 8454401));
}
@Override
protected Pattern getSupportedDeviceName() {
return Pattern.compile(HuamiConst.AMAZFIT_BIP5_NAME + ".*");
}
@Override
public boolean supportsContinuousFindDevice() {
return true;

View File

@ -19,7 +19,6 @@ package nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitcheetahpro;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
@ -37,11 +36,6 @@ public class AmazfitCheetahProCoordinator extends ZeppOsCoordinator {
return new HashSet<>(Arrays.asList(8126720, 8126721));
}
@Override
protected Pattern getSupportedDeviceName() {
return Pattern.compile(HuamiConst.AMAZFIT_CHEETAH_PRO_NAME + ".*");
}
@Override
public int getDeviceNameResource() {
return R.string.devicetype_amazfit_cheetah_pro;

View File

@ -19,7 +19,6 @@ package nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitcheetahround;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
@ -47,11 +46,6 @@ public class AmazfitCheetahRoundCoordinator extends ZeppOsCoordinator {
return R.string.devicetype_amazfit_cheetah_round;
}
@Override
protected Pattern getSupportedDeviceName() {
return Pattern.compile(HuamiConst.AMAZFIT_CHEETAH_ROUND_NAME + ".*");
}
@Override
public boolean supportsContinuousFindDevice() {
return true;

View File

@ -19,7 +19,6 @@ package nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitcheetahsquare;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
@ -42,11 +41,6 @@ public class AmazfitCheetahSquareCoordinator extends ZeppOsCoordinator {
return new HashSet<>(Collections.singletonList(8257793));
}
@Override
protected Pattern getSupportedDeviceName() {
return Pattern.compile(HuamiConst.AMAZFIT_CHEETAH_SQUARE_NAME + ".*");
}
@Override
public boolean supportsContinuousFindDevice() {
return true;

View File

@ -19,7 +19,6 @@ package nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitfalcon;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
@ -47,11 +46,6 @@ public class AmazfitFalconCoordinator extends ZeppOsCoordinator {
return R.string.devicetype_amazfit_falcon;
}
@Override
protected Pattern getSupportedDeviceName() {
return Pattern.compile(HuamiConst.AMAZFIT_FALCON_NAME + ".*");
}
@Override
public boolean sendAgpsAsFileTransfer() {
return false;

View File

@ -16,8 +16,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgtr3;
import androidx.annotation.NonNull;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@ -26,7 +24,6 @@ import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.zeppos.ZeppOsCoordinator;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
public class AmazfitGTR3Coordinator extends ZeppOsCoordinator {
@Override
@ -39,13 +36,6 @@ public class AmazfitGTR3Coordinator extends ZeppOsCoordinator {
return new HashSet<>(Arrays.asList(226, 227));
}
@NonNull
@Override
public boolean supports(final GBDeviceCandidate candidate) {
final String name = candidate.getName();
return name.startsWith(HuamiConst.AMAZFIT_GTR3_NAME) && !name.contains("Pro");
}
@Override
public int getDeviceNameResource() {
return R.string.devicetype_amazfit_gtr3;

View File

@ -19,7 +19,6 @@ package nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgtr3pro;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
@ -37,11 +36,6 @@ public class AmazfitGTR3ProCoordinator extends ZeppOsCoordinator {
return new HashSet<>(Arrays.asList(229, 230, 6095106));
}
@Override
protected Pattern getSupportedDeviceName() {
return Pattern.compile(HuamiConst.AMAZFIT_GTR3_PRO_NAME + ".*");
}
@Override
public int getDeviceNameResource() {
return R.string.devicetype_amazfit_gtr3_pro;

View File

@ -24,7 +24,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
@ -42,11 +41,6 @@ public class AmazfitGTR4Coordinator extends ZeppOsCoordinator {
return new HashSet<>(Arrays.asList(7930112, 7930113, 7864577));
}
@Override
protected Pattern getSupportedDeviceName() {
return Pattern.compile(HuamiConst.AMAZFIT_GTR4_NAME + ".*");
}
@Override
protected Map<Integer, String> getCrcMap() {
return new HashMap<Integer, String>() {{

View File

@ -19,7 +19,6 @@ package nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgtrmini;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
@ -42,11 +41,6 @@ public class AmazfitGTRMiniCoordinator extends ZeppOsCoordinator {
return R.string.devicetype_amazfit_gtr_mini;
}
@Override
protected Pattern getSupportedDeviceName() {
return Pattern.compile(HuamiConst.AMAZFIT_GTR_MINI_NAME + ".*");
}
@Override
public boolean sendAgpsAsFileTransfer() {
// Even though it's a Zepp OS 2.0 device, it doesn't seem to support the AGPS service

View File

@ -19,7 +19,6 @@ package nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgts3;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
@ -37,11 +36,6 @@ public class AmazfitGTS3Coordinator extends ZeppOsCoordinator {
return new HashSet<>(Arrays.asList(224, 225));
}
@Override
protected Pattern getSupportedDeviceName() {
return Pattern.compile(HuamiConst.AMAZFIT_GTS3_NAME + ".*");
}
@Override
public boolean sendAgpsAsFileTransfer() {
return false;

View File

@ -24,7 +24,6 @@ import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.zeppos.ZeppOsCoordinator;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
public class AmazfitGTS4Coordinator extends ZeppOsCoordinator {
@Override
@ -37,12 +36,6 @@ public class AmazfitGTS4Coordinator extends ZeppOsCoordinator {
return new HashSet<>(Arrays.asList(7995648, 7995649));
}
@Override
public boolean supports(final GBDeviceCandidate candidate) {
final String name = candidate.getName();
return name.startsWith(HuamiConst.AMAZFIT_GTS4_NAME) && !name.contains("Mini");
}
@Override
public boolean supportsContinuousFindDevice() {
return true;

View File

@ -19,7 +19,6 @@ package nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgts4mini;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
@ -37,12 +36,6 @@ public class AmazfitGTS4MiniCoordinator extends ZeppOsCoordinator {
return new HashSet<>(Arrays.asList(246, 247));
}
@Override
protected Pattern getSupportedDeviceName() {
return Pattern.compile(HuamiConst.AMAZFIT_GTS4_MINI_NAME + ".*");
}
@Override
public boolean sendAgpsAsFileTransfer() {
return false;

View File

@ -19,7 +19,6 @@ package nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfittrex2;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
@ -37,11 +36,6 @@ public class AmazfitTRex2Coordinator extends ZeppOsCoordinator {
return new HashSet<>(Arrays.asList(418, 419));
}
@Override
protected Pattern getSupportedDeviceName() {
return Pattern.compile(HuamiConst.AMAZFIT_TREX_2_NAME + ".*");
}
@Override
public int getDeviceNameResource() {
return R.string.devicetype_amazfit_trex_2;

View File

@ -19,7 +19,6 @@ package nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfittrexultra;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
@ -42,11 +41,6 @@ public class AmazfitTRexUltraCoordinator extends ZeppOsCoordinator {
return R.string.devicetype_amazfit_trex_ultra;
}
@Override
protected Pattern getSupportedDeviceName() {
return Pattern.compile(HuamiConst.AMAZFIT_TREX_ULTRA + ".*");
}
@Override
public boolean supportsContinuousFindDevice() {
return true;

View File

@ -26,7 +26,6 @@ import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.zeppos.ZeppOsCoordinator;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
public class MiBand7Coordinator extends ZeppOsCoordinator {
@Override
@ -50,12 +49,6 @@ public class MiBand7Coordinator extends ZeppOsCoordinator {
}};
}
@Override
public boolean supports(final GBDeviceCandidate candidate) {
final String name = candidate.getName();
return name.startsWith(HuamiConst.XIAOMI_SMART_BAND7_NAME) && !name.contains("Pro");
}
@Override
public boolean supportsAgpsUpdates() {
return false;

View File

@ -32,6 +32,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AppManagerActivity;
@ -83,6 +84,15 @@ public abstract class ZeppOsCoordinator extends HuamiCoordinator {
return Collections.emptyMap();
}
@Override
protected final Pattern getSupportedDeviceName() {
// Most devices use the exact bluetooth name
// Some devices have a " XXXX" suffix with the last 4 digits of mac address (eg. Mi Band 7)
// *However*, some devices broadcast a 2nd bluetooth device with "-XXXX" suffix, which is only
// used for calls and Gadgetbridge can't use for pairing.
return Pattern.compile("^" + getDeviceBluetoothName() + "( [A-Z0-9]{4})?$");
}
@NonNull
@Override
public final Class<? extends DeviceSupport> getDeviceSupportClass() {