From ef1d38d9d32fee0acb1e33a68a6aa601b3059cd2 Mon Sep 17 00:00:00 2001 From: Daniel Dakhno Date: Fri, 29 Sep 2023 18:50:32 +0300 Subject: [PATCH] Device Manager: replaced getSupportedType with supports method Huami: introduced getSupportedDeviceName Huami: implemented getSupportedDeviceName Huami: fixed typo Device manager: added error on empty getSupportedDeviceName and empty supports() Device manager: migrated more devices to getSupportedDeviceName Device manager: simplified default supports implementation Device manager: added caching for getSupportedDeviceName pattern Device manager: added caching DeviceType resolution Device manager: changed pattern matching find()->matches() Device manager: use Candidate as caching key Device manager: more verbose variable initialization Device manager: fixed typo Device manager: removed device caching from DeviceHelper Gradle: removed protoc binary Device manager: moved more devices to getSupportedDeviceName Device manager: reduced usages of String.format Device Vesc: removed multiple device types Device management: regex improvements Makibes HR3: fixed device recognition regex --- .../devices/AbstractDeviceCoordinator.java | 25 ++++++++++++++++-- .../devices/DeviceCoordinator.java | 11 -------- .../devices/UnknownDeviceCoordinator.java | 4 +-- .../AsteroidOSDeviceCoordinator.java | 9 +++---- .../devices/banglejs/BangleJSCoordinator.java | 17 +++--------- .../coordinator/BinarySensorCoordinator.java | 7 +++-- .../gb6900/CasioGB6900DeviceCoordinator.java | 16 ++++-------- .../gbx100/CasioGBX100DeviceCoordinator.java | 17 +++--------- .../CasioGMWB5000DeviceCoordinator.java | 17 +++--------- .../CasioGWB5600DeviceCoordinator.java | 22 +++------------- .../devices/domyos/DomyosT540Coordinator.java | 10 +++---- .../fitpro/FitProDeviceCoordinator.java | 25 +++--------------- .../flipper/zero/FlipperZeroCoordinator.java | 6 ++--- .../GalaxyBuds2DeviceCoordinator.java | 16 +++--------- .../GalaxyBuds2ProDeviceCoordinator.java | 16 +++--------- .../GalaxyBudsDeviceCoordinator.java | 16 +++--------- .../GalaxyBudsLiveDeviceCoordinator.java | 16 +++--------- .../GalaxyBudsProDeviceCoordinator.java | 16 +++--------- .../devices/hplus/EXRIZUK8Coordinator.java | 13 +++------- .../devices/hplus/HPlusCoordinator.java | 14 +++------- .../devices/hplus/MakibesF68Coordinator.java | 6 ++--- .../devices/hplus/Q8Coordinator.java | 13 +++------- .../devices/hplus/SG2Coordinator.java | 6 ++--- .../amazfitband5/AmazfitBand5Coordinator.java | 17 +++--------- .../amazfitband7/AmazfitBand7Coordinator.java | 17 +++--------- .../amazfitbip/AmazfitBipCoordinator.java | 15 +++-------- .../amazfitbip/AmazfitBipLiteCoordinator.java | 15 +++-------- .../AmazfitBip3ProCoordinator.java | 15 +++-------- .../amazfitbip5/AmazfitBip5Coordinator.java | 16 +++--------- .../amazfitbips/AmazfitBipSCoordinator.java | 17 +++--------- .../AmazfitBipSLiteCoordinator.java | 15 +++-------- .../amazfitbipu/AmazfitBipUCoordinator.java | 15 +++-------- .../AmazfitBipUProCoordinator.java | 15 +++-------- .../AmazfitCheetahProCoordinator.java | 16 +++--------- .../AmazfitCheetahRoundCoordinator.java | 16 +++--------- .../AmazfitCheetahSquareCoordinator.java | 16 +++--------- .../amazfitcor/AmazfitCorCoordinator.java | 15 +++-------- .../amazfitcor2/AmazfitCor2Coordinator.java | 15 +++-------- .../AmazfitFalconCoordinator.java | 16 +++--------- .../amazfitgtr/AmazfitGTRCoordinator.java | 16 +++--------- .../amazfitgtr/AmazfitGTRLiteCoordinator.java | 15 +++-------- .../amazfitgtr2/AmazfitGTR2Coordinator.java | 15 +++-------- .../amazfitgtr2/AmazfitGTR2eCoordinator.java | 15 +++-------- .../amazfitgtr3/AmazfitGTR3Coordinator.java | 6 ++--- .../AmazfitGTR3ProCoordinator.java | 16 +++--------- .../amazfitgtr4/AmazfitGTR4Coordinator.java | 16 +++--------- .../AmazfitGTRMiniCoordinator.java | 16 +++--------- .../amazfitgts/AmazfitGTSCoordinator.java | 15 +++-------- .../amazfitgts2/AmazfitGTS2Coordinator.java | 15 +++-------- .../AmazfitGTS2MiniCoordinator.java | 15 +++-------- .../amazfitgts2/AmazfitGTS2eCoordinator.java | 15 +++-------- .../amazfitgts3/AmazfitGTS3Coordinator.java | 16 +++--------- .../amazfitgts4/AmazfitGTS4Coordinator.java | 6 ++--- .../AmazfitGTS4MiniCoordinator.java | 16 +++--------- .../amazfitneo/AmazfitNeoCoordinator.java | 15 +++-------- .../amazfitpop/AmazfitPopCoordinator.java | 15 +++-------- .../AmazfitPopProCoordinator.java | 15 +++-------- .../amazfittrex/AmazfitTRexCoordinator.java | 15 +++-------- .../amazfittrex2/AmazfitTRex2Coordinator.java | 16 +++--------- .../AmazfitTRexProCoordinator.java | 15 +++-------- .../AmazfitTRexUltraCoordinator.java | 16 +++--------- .../AmazfitVergeLCoordinator.java | 16 +++--------- .../huami/amazfitx/AmazfitXCoordinator.java | 18 +++---------- .../huami/miband2/MiBand2Coordinator.java | 16 +++--------- .../huami/miband2/MiBand2HRXCoordinator.java | 17 +++++------- .../huami/miband3/MiBand3Coordinator.java | 18 +++++-------- .../huami/miband4/MiBand4Coordinator.java | 16 +++--------- .../huami/miband5/MiBand5Coordinator.java | 15 +++-------- .../huami/miband6/MiBand6Coordinator.java | 15 +++-------- .../huami/miband7/MiBand7Coordinator.java | 16 +++--------- .../devices/huami/zeppe/ZeppECoordinator.java | 15 +++-------- .../devices/id115/ID115Coordinator.java | 8 +++--- .../devices/itag/ITagCoordinator.java | 12 +++------ .../devices/jyou/BFH16DeviceCoordinator.java | 15 +++-------- .../TeclastH30/TeclastH30Coordinator.java | 26 ++++++------------- .../devices/jyou/y5/Y5Coordinator.java | 17 +++--------- ...BohemicSmartBraceletDeviceCoordinator.java | 11 +++----- .../devices/lefun/LefunDeviceCoordinator.java | 6 ++--- .../WatchXPlusDeviceCoordinator.java | 14 +++++----- .../devices/liveview/LiveviewCoordinator.java | 12 ++++----- .../makibeshr3/MakibesHR3Coordinator.java | 20 +++----------- .../devices/miband/MiBandCoordinator.java | 12 ++++----- .../MijiaLywsd02Coordinator.java | 11 +++----- .../miscale2/MiScale2DeviceCoordinator.java | 16 +++--------- .../devices/no1f1/No1F1Coordinator.java | 14 +++------- .../devices/nothing/Ear1Coordinator.java | 10 +++---- .../devices/nut/NutCoordinator.java | 12 +++------ .../devices/pebble/PebbleCoordinator.java | 10 +++---- .../pinetime/PineTimeJFCoordinator.java | 11 +++----- .../devices/qc35/QC35Coordinator.java | 10 +++---- .../devices/qhybrid/QHybridCoordinator.java | 10 +++---- .../devices/roidmi/Roidmi1Coordinator.java | 6 ++--- .../devices/roidmi/Roidmi3Coordinator.java | 8 +++--- .../devices/smaq2oss/SMAQ2OSSCoordinator.java | 15 +++-------- .../devices/soflow/SoFlowCoordinator.java | 11 +++----- .../SonyLinkBudsSCoordinator.java | 10 +++---- .../SonyWF1000XM3Coordinator.java | 11 +++----- .../SonyWF1000XM4Coordinator.java | 11 +++----- .../SonyWF1000XM5Coordinator.java | 11 +++----- .../coordinators/SonyWFSP800NCoordinator.java | 10 +++---- .../SonyWH1000XM2Coordinator.java | 10 +++---- .../SonyWH1000XM3Coordinator.java | 11 +++----- .../SonyWH1000XM4Coordinator.java | 11 +++----- .../SonyWH1000XM5Coordinator.java | 10 +++---- .../sony/wena3/SonyWena3Coordinator.java | 10 +++---- .../sonyswr12/SonySWR12DeviceCoordinator.java | 13 +++------- .../supercars/SuperCarsCoordinator.java | 18 +++---------- .../devices/test/TestDeviceCoordinator.java | 4 +-- .../devices/tlw64/TLW64Coordinator.java | 12 +++------ .../um25/Coordinator/UM25Coordinator.java | 8 +++--- .../devices/vesc/VescCoordinator.java | 12 +++------ .../vibratissimo/VibratissimoCoordinator.java | 10 +++---- .../vivomovehr/VivomoveHrCoordinator.java | 7 +++-- .../devices/waspos/WaspOSCoordinator.java | 19 +++----------- .../watch9/Watch9DeviceCoordinator.java | 12 ++++----- .../WithingsSteelHRDeviceCoordinator.java | 6 ++--- .../devices/xwatch/XWatchCoordinator.java | 12 ++++----- .../devices/zetime/ZeTimeCoordinator.java | 11 +++----- .../gadgetbridge/model/DeviceType.java | 3 +-- .../devices/vesc/VescDeviceSupport.java | 16 +++++------- .../protocol/impl/MockSonyCoordinator.java | 4 +-- 121 files changed, 466 insertions(+), 1154 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java index 06fa1bdaf..d99749459 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java @@ -42,6 +42,7 @@ import java.util.Collection; import java.util.Collections; import java.util.EnumSet; import java.util.List; +import java.util.regex.Pattern; import de.greenrobot.dao.query.QueryBuilder; import nodomain.freeyourgadget.gadgetbridge.GBApplication; @@ -76,9 +77,29 @@ import nodomain.freeyourgadget.gadgetbridge.util.Prefs; public abstract class AbstractDeviceCoordinator implements DeviceCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AbstractDeviceCoordinator.class); + private Pattern supportedDeviceName = null; + /** + * This method should return a ReGexp pattern that will matched against a found device + * to check whether this coordinator supports that device. + * If more sophisticated logic is needed to determine device support, the supports(GBDeviceCandidate) + * should be overridden. + * + * @return Pattern + * */ + protected Pattern getSupportedDeviceName(){ + return null; + } + @Override - public final boolean supports(GBDeviceCandidate candidate) { - return getSupportedType(candidate).isSupported(); + public boolean supports(GBDeviceCandidate candidate) { + if(supportedDeviceName == null){ + supportedDeviceName = getSupportedDeviceName(); + } + if(supportedDeviceName == null){ + throw new RuntimeException(getClass() + " should either override getSupportedDeviceName or supports(GBDeviceCandidate)"); + } + + return supportedDeviceName.matcher(candidate.getName()).matches(); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java index 4ccaae387..e6d310550 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java @@ -112,17 +112,6 @@ public interface DeviceCoordinator { } } - /** - * Checks whether this coordinator handles the given candidate. - * Returns the supported device type for the given candidate or - * DeviceType.UNKNOWN - * - * @param candidate - * @return the supported device type for the given candidate. - */ - @NonNull - DeviceType getSupportedType(GBDeviceCandidate candidate); - /** * Returns the type of connection, Classic of BLE * diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/UnknownDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/UnknownDeviceCoordinator.java index ba7662739..527f50879 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/UnknownDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/UnknownDeviceCoordinator.java @@ -108,8 +108,8 @@ public class UnknownDeviceCoordinator extends AbstractDeviceCoordinator { @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - return DeviceType.UNKNOWN; + public boolean supports(GBDeviceCandidate candidate) { + return false; } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/asteroidos/AsteroidOSDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/asteroidos/AsteroidOSDeviceCoordinator.java index 723a48f89..7330f5ee7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/asteroidos/AsteroidOSDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/asteroidos/AsteroidOSDeviceCoordinator.java @@ -4,7 +4,6 @@ import android.app.Activity; import android.bluetooth.le.ScanFilter; import android.content.Context; import android.net.Uri; -import android.os.Parcel; import android.os.ParcelUuid; import androidx.annotation.NonNull; @@ -67,16 +66,16 @@ public class AsteroidOSDeviceCoordinator extends AbstractDeviceCoordinator { @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { + public boolean supports(GBDeviceCandidate candidate) { if (candidate.supportsService(AsteroidOSConstants.SERVICE_UUID)) { - return DeviceType.ASTEROIDOS; + return true; } for (String name : AsteroidOSConstants.SUPPORTED_DEVICE_CODENAMES) { if (candidate.getName().equals(name)) { - return DeviceType.ASTEROIDOS; + return true; } } - return DeviceType.UNKNOWN; + return false; } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/banglejs/BangleJSCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/banglejs/BangleJSCoordinator.java index ea853787d..06f674a14 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/banglejs/BangleJSCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/banglejs/BangleJSCoordinator.java @@ -31,6 +31,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.BuildConfig; import nodomain.freeyourgadget.gadgetbridge.R; @@ -64,21 +65,9 @@ public class BangleJSCoordinator extends AbstractBLEDeviceCoordinator { return Collections.singletonList(filter); } - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - /* Filter by Espruino devices to avoid getting - the device chooser full of spam devices. */ - if (name != null && ( - name.startsWith("Bangle.js") || - name.startsWith("Pixl.js") || - name.startsWith("Puck.js") || - name.startsWith("MDBT42Q") || - name.startsWith("Espruino"))) - return DeviceType.BANGLEJS; - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Bangle\\.js.*|Pixl\\.js.*|Puck\\.js.*|MDBT42Q.*|Espruino.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/binary_sensor/coordinator/BinarySensorCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/binary_sensor/coordinator/BinarySensorCoordinator.java index 1e296c221..3284935ef 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/binary_sensor/coordinator/BinarySensorCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/binary_sensor/coordinator/BinarySensorCoordinator.java @@ -46,14 +46,13 @@ public class BinarySensorCoordinator extends AbstractBLEDeviceCoordinator { @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - Log.d("coordinator", "candidate name: " + candidate.getName()); + public boolean supports(GBDeviceCandidate candidate) { for(ParcelUuid service : candidate.getServiceUuids()){ if(service.getUuid().toString().equals(BinarySensorSupport.BINARY_SENSOR_SERVICE_UUID)){ - return DeviceType.BINARY_SENSOR; + return true; }; } - return DeviceType.UNKNOWN; + return false; } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gb6900/CasioGB6900DeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gb6900/CasioGB6900DeviceCoordinator.java index 8d9b5e1eb..ac40d2351 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gb6900/CasioGB6900DeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gb6900/CasioGB6900DeviceCoordinator.java @@ -27,6 +27,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import androidx.annotation.NonNull; + +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; @@ -44,18 +47,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gb6900.CasioGB public class CasioGB6900DeviceCoordinator extends CasioDeviceCoordinator { protected static final Logger LOG = LoggerFactory.getLogger(CasioGB6900DeviceCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - if (name != null) { - if (name.startsWith("CASIO") && (name.contains("6900B") || name.contains("5600B") || - name.contains("STB-1000"))) { - return DeviceType.CASIOGB6900; - } - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("CASIO.*(6900B|5600B|STB-1000).*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gbx100/CasioGBX100DeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gbx100/CasioGBX100DeviceCoordinator.java index c3febfb7e..52bb461d4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gbx100/CasioGBX100DeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gbx100/CasioGBX100DeviceCoordinator.java @@ -28,13 +28,14 @@ import org.slf4j.LoggerFactory; import androidx.annotation.NonNull; +import java.util.regex.Pattern; + import de.greenrobot.dao.query.QueryBuilder; import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioDeviceCoordinator; -import nodomain.freeyourgadget.gadgetbridge.devices.casio.gbx100.CasioGBX100SampleProvider; import nodomain.freeyourgadget.gadgetbridge.entities.CasioGBX100ActivitySampleDao; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.entities.Device; @@ -48,19 +49,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gbx100.CasioGB public class CasioGBX100DeviceCoordinator extends CasioDeviceCoordinator { protected static final Logger LOG = LoggerFactory.getLogger(CasioGBX100DeviceCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - if (name != null) { - if (name.startsWith("CASIO") && (name.endsWith("GBX-100") || - name.endsWith("GBD-200") || name.endsWith("GBD-100") || - name.endsWith("GBD-H1000"))) { - return DeviceType.CASIOGBX100; - } - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("CASIO.*(GBX-100|GBD-100|GBD-200|GBD-H1000)"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gwb5600/CasioGMWB5000DeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gwb5600/CasioGMWB5000DeviceCoordinator.java index 135a55093..e645980eb 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gwb5600/CasioGMWB5000DeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gwb5600/CasioGMWB5000DeviceCoordinator.java @@ -20,25 +20,16 @@ package nodomain.freeyourgadget.gadgetbridge.devices.casio.gwb5600; import androidx.annotation.NonNull; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; -import nodomain.freeyourgadget.gadgetbridge.devices.casio.gwb5600.CasioGWB5600DeviceCoordinator; - public class CasioGMWB5000DeviceCoordinator extends CasioGWB5600DeviceCoordinator { - - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - if (name != null) { - if (name.equals("CASIO GMW-B5000")) { - return DeviceType.CASIOGMWB5000; - } - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("CASIO GMW-B5000"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gwb5600/CasioGWB5600DeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gwb5600/CasioGWB5600DeviceCoordinator.java index 0114348db..5e1abf870 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gwb5600/CasioGWB5600DeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gwb5600/CasioGWB5600DeviceCoordinator.java @@ -18,19 +18,15 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.casio.gwb5600; -import java.util.Collection; -import java.util.Collections; - import android.app.Activity; import android.content.Context; import android.net.Uri; -import android.bluetooth.le.ScanFilter; -import android.os.ParcelUuid; import androidx.annotation.NonNull; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; -import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; @@ -40,24 +36,14 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; -import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioConstants; import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioDeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gwb5600.CasioGWB5600DeviceSupport; public class CasioGWB5600DeviceCoordinator extends CasioDeviceCoordinator { - - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - if (name != null) { - if (name.equals("CASIO GW-B5600")) { - return DeviceType.CASIOGWB5600; - } - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("CASIO GW-B5600"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/domyos/DomyosT540Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/domyos/DomyosT540Coordinator.java index ea0a089ba..e4bcdc33e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/domyos/DomyosT540Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/domyos/DomyosT540Coordinator.java @@ -24,6 +24,7 @@ import android.net.Uri; import androidx.annotation.NonNull; import java.util.EnumSet; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator; @@ -40,14 +41,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.ServiceDeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.domyos.DomyosT540Support; public class DomyosT540Coordinator extends AbstractBLEDeviceCoordinator { - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - if (name != null && name.startsWith("Domyos-TC-9610")) { - return DeviceType.DOMYOS_T540; - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Domyos-TC-9610.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/fitpro/FitProDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/fitpro/FitProDeviceCoordinator.java index 742859f0c..16ee11baa 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/fitpro/FitProDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/fitpro/FitProDeviceCoordinator.java @@ -20,7 +20,6 @@ package nodomain.freeyourgadget.gadgetbridge.devices.fitpro; import android.app.Activity; import android.content.Context; import android.net.Uri; -import android.os.ParcelUuid; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -29,6 +28,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.EnumSet; +import java.util.regex.Pattern; import de.greenrobot.dao.query.QueryBuilder; import nodomain.freeyourgadget.gadgetbridge.GBException; @@ -58,28 +58,9 @@ public class FitProDeviceCoordinator extends AbstractBLEDeviceCoordinator { qb.where(FitProActivitySampleDao.Properties.DeviceId.eq(deviceId)).buildDelete().executeDeleteWithoutDetachingEntities(); } - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - - if (name != null && ( - name.startsWith("M6") || - name.startsWith("M4") || - name.equals("LH716") || - name.equals("Sunset 6") || - name.equals("Watch7") || - name.equals("Fit1900")) - ) { - return DeviceType.FITPRO; - } - - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("M6.*|M4.*|LH716|Sunset 6|Watch7|Fit1900"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/flipper/zero/FlipperZeroCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/flipper/zero/FlipperZeroCoordinator.java index dd671f8e4..70a9cd81e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/flipper/zero/FlipperZeroCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/flipper/zero/FlipperZeroCoordinator.java @@ -31,11 +31,11 @@ public class FlipperZeroCoordinator extends AbstractBLEDeviceCoordinator { @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { + public boolean supports(GBDeviceCandidate candidate) { if(candidate.supportsService(UUID.fromString("00003082-0000-1000-8000-00805f9b34fb"))){ - return DeviceType.FLIPPER_ZERO; // need to filter for flipper here + return true; // need to filter for flipper here } - return DeviceType.UNKNOWN; + return false; } @Nullable diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBuds2DeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBuds2DeviceCoordinator.java index a7d0bc696..869cbffb8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBuds2DeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBuds2DeviceCoordinator.java @@ -2,6 +2,8 @@ package nodomain.freeyourgadget.gadgetbridge.devices.galaxy_buds; import androidx.annotation.NonNull; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsCustomizer; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; @@ -10,19 +12,9 @@ import nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; public class GalaxyBuds2DeviceCoordinator extends GalaxyBudsGenericCoordinator { - - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - - String name = candidate.getName(); - - if (name != null && ( - name.startsWith("Galaxy Buds2 (") - )) { - return DeviceType.GALAXY_BUDS2; - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Galaxy Buds2 \\(.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBuds2ProDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBuds2ProDeviceCoordinator.java index 8f4ee2d89..7d63455c9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBuds2ProDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBuds2ProDeviceCoordinator.java @@ -2,6 +2,8 @@ package nodomain.freeyourgadget.gadgetbridge.devices.galaxy_buds; import androidx.annotation.NonNull; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsCustomizer; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; @@ -10,19 +12,9 @@ import nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; public class GalaxyBuds2ProDeviceCoordinator extends GalaxyBudsGenericCoordinator { - - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - - String name = candidate.getName(); - - if (name != null && ( - name.startsWith("Galaxy Buds2 Pro") - )) { - return DeviceType.GALAXY_BUDS2_PRO; - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Galaxy Buds2 Pro.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBudsDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBudsDeviceCoordinator.java index f19dbfa0a..10a78a244 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBudsDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBudsDeviceCoordinator.java @@ -2,6 +2,8 @@ package nodomain.freeyourgadget.gadgetbridge.devices.galaxy_buds; import androidx.annotation.NonNull; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; @@ -9,19 +11,9 @@ import nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; public class GalaxyBudsDeviceCoordinator extends GalaxyBudsGenericCoordinator { - - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - - String name = candidate.getName(); - - if (name != null && ( - name.startsWith("Galaxy Buds (") - )) { - return DeviceType.GALAXY_BUDS; - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Galaxy Buds \\(.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBudsLiveDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBudsLiveDeviceCoordinator.java index 666292b21..0b755fab1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBudsLiveDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBudsLiveDeviceCoordinator.java @@ -2,6 +2,8 @@ package nodomain.freeyourgadget.gadgetbridge.devices.galaxy_buds; import androidx.annotation.NonNull; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; @@ -9,19 +11,9 @@ import nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; public class GalaxyBudsLiveDeviceCoordinator extends GalaxyBudsGenericCoordinator { - - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - - String name = candidate.getName(); - - if (name != null && ( - name.startsWith("Galaxy Buds Live (") - )) { - return DeviceType.GALAXY_BUDS_LIVE; - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Galaxy Buds Live \\(.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBudsProDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBudsProDeviceCoordinator.java index 27c7a2ac5..334cf2ae4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBudsProDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBudsProDeviceCoordinator.java @@ -2,6 +2,8 @@ package nodomain.freeyourgadget.gadgetbridge.devices.galaxy_buds; import androidx.annotation.NonNull; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsCustomizer; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; @@ -10,19 +12,9 @@ import nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; public class GalaxyBudsProDeviceCoordinator extends GalaxyBudsGenericCoordinator { - - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - - String name = candidate.getName(); - - if (name != null && ( - name.startsWith("Galaxy Buds Pro (") - )) { - return DeviceType.GALAXY_BUDS_PRO; - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Galaxy Buds Pro \\(.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/EXRIZUK8Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/EXRIZUK8Coordinator.java index 3e37b078e..eefc77daf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/EXRIZUK8Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/EXRIZUK8Coordinator.java @@ -23,6 +23,8 @@ package nodomain.freeyourgadget.gadgetbridge.devices.hplus; import androidx.annotation.NonNull; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; @@ -31,16 +33,9 @@ import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; * Pseudo Coordinator for the EXRIZU K8, a sub type of the HPLUS devices */ public class EXRIZUK8Coordinator extends HPlusCoordinator { - - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - if(name != null && name.startsWith("iRun ")){ - return DeviceType.EXRIZUK8; - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("iRun .*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusCoordinator.java index 00fab4311..41e3e6b3a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusCoordinator.java @@ -17,13 +17,11 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.hplus; -import android.annotation.TargetApi; import android.app.Activity; import android.bluetooth.le.ScanFilter; import android.content.Context; import android.content.SharedPreferences; import android.net.Uri; -import android.os.Build; import android.os.ParcelUuid; import org.slf4j.Logger; @@ -32,6 +30,7 @@ import org.slf4j.LoggerFactory; import java.util.Collection; import java.util.Collections; import java.util.Locale; +import java.util.regex.Pattern; import androidx.annotation.NonNull; @@ -53,7 +52,6 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample; import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport; -import nodomain.freeyourgadget.gadgetbridge.service.ServiceDeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.hplus.HPlusSupport; import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs; @@ -72,15 +70,9 @@ public class HPlusCoordinator extends AbstractBLEDeviceCoordinator { return Collections.singletonList(filter); } - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - if (name != null && name.startsWith("HPLUS")) { - return DeviceType.HPLUS; - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("HPLUS.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/MakibesF68Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/MakibesF68Coordinator.java index 263d81a8b..ecbd61a38 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/MakibesF68Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/MakibesF68Coordinator.java @@ -34,13 +34,13 @@ public class MakibesF68Coordinator extends HPlusCoordinator { @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { + public boolean supports(GBDeviceCandidate candidate) { String name = candidate.getName(); if(name != null && name.startsWith("SPORT") && !name.startsWith("SPORTAGE")){ - return DeviceType.MAKIBESF68; + return true; } - return DeviceType.UNKNOWN; + return false; } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/Q8Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/Q8Coordinator.java index 5ac088f41..3beec9cff 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/Q8Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/Q8Coordinator.java @@ -23,6 +23,8 @@ package nodomain.freeyourgadget.gadgetbridge.devices.hplus; import androidx.annotation.NonNull; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; @@ -31,16 +33,9 @@ import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; * Pseudo Coordinator for the Q8, a sub type of the HPLUS devices */ public class Q8Coordinator extends HPlusCoordinator { - - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - if(name != null && name.startsWith("Q8")){ - return DeviceType.Q8; - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Q8.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/SG2Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/SG2Coordinator.java index 7ef84403b..977a42e59 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/SG2Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/SG2Coordinator.java @@ -31,16 +31,16 @@ public class SG2Coordinator extends HPlusCoordinator { @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { + public boolean supports(GBDeviceCandidate candidate) { String name = candidate.getName(); if (name != null && name.startsWith("SG2")) { HPlusCoordinator.setNotificationLinesNumber(candidate.getDevice().getAddress(), 9); HPlusCoordinator.setUnicodeSupport(candidate.getDevice().getAddress(), true); HPlusCoordinator.setDisplayIncomingMessageIcon(candidate.getDevice().getAddress(), false); - return DeviceType.SG2; + return true; } - return DeviceType.UNKNOWN; + return false; } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitband5/AmazfitBand5Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitband5/AmazfitBand5Coordinator.java index 1a79ea789..9c627479b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitband5/AmazfitBand5Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitband5/AmazfitBand5Coordinator.java @@ -25,6 +25,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; @@ -38,22 +40,11 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitband5.A public class AmazfitBand5Coordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitBand5Coordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && name.equalsIgnoreCase(HuamiConst.AMAZFIT_BAND5_NAME)) { - return DeviceType.AMAZFITBAND5; - } - } catch (SecurityException ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; - + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.AMAZFIT_BAND5_NAME, Pattern.CASE_INSENSITIVE); } - @Override public InstallHandler findInstallHandler(Uri uri, Context context) { AmazfitBand5FWInstallHandler handler = new AmazfitBand5FWInstallHandler(uri, context); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitband7/AmazfitBand7Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitband7/AmazfitBand7Coordinator.java index 368923f19..64d480966 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitband7/AmazfitBand7Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitband7/AmazfitBand7Coordinator.java @@ -24,6 +24,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; @@ -37,21 +39,10 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitband7.A public class AmazfitBand7Coordinator extends Huami2021Coordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitBand7Coordinator.class); - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - try { - final String name = candidate.getName(); - if (name != null && name.startsWith(HuamiConst.AMAZFIT_BAND7_NAME)) { - return DeviceType.AMAZFITBAND7; - } - } catch (SecurityException e) { - LOG.error("unable to check device support", e); - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.AMAZFIT_BAND7_NAME + ".*", Pattern.CASE_INSENSITIVE); } - @NonNull @Override public Class getDeviceSupportClass() { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip/AmazfitBipCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip/AmazfitBipCoordinator.java index 51a259652..ad346a1fb 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip/AmazfitBipCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip/AmazfitBipCoordinator.java @@ -25,6 +25,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; @@ -37,18 +39,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.Ama public class AmazfitBipCoordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitBipCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && (name.equalsIgnoreCase("Amazfit Bip Watch"))) { - return DeviceType.AMAZFITBIP; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit Bip Watch", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip/AmazfitBipLiteCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip/AmazfitBipLiteCoordinator.java index d4b5bcdf7..81913467a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip/AmazfitBipLiteCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip/AmazfitBipLiteCoordinator.java @@ -25,6 +25,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; @@ -36,18 +38,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.Ama public class AmazfitBipLiteCoordinator extends AmazfitBipCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitBipLiteCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && name.equalsIgnoreCase("Amazfit Bip Lite")) { - return DeviceType.AMAZFITBIP_LITE; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit Bip Lite", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip3pro/AmazfitBip3ProCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip3pro/AmazfitBip3ProCoordinator.java index 76cb3b3c6..464c8617e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip3pro/AmazfitBip3ProCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip3pro/AmazfitBip3ProCoordinator.java @@ -24,6 +24,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; @@ -36,18 +38,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip3pro public class AmazfitBip3ProCoordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitBip3ProCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - try { - final String name = candidate.getName(); - if (name != null && name.equalsIgnoreCase("Amazfit Bip 3 Pro")) { - return DeviceType.AMAZFITBIP3PRO; - } - } catch (final Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit Bip 3 Pro", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip5/AmazfitBip5Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip5/AmazfitBip5Coordinator.java index 0aeeb5803..838615d89 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip5/AmazfitBip5Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip5/AmazfitBip5Coordinator.java @@ -24,6 +24,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; @@ -48,19 +50,9 @@ public class AmazfitBip5Coordinator extends Huami2021Coordinator { return AmazfitBip5Support.class; } - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - try { - final String name = candidate.getName(); - if (name != null && name.startsWith(HuamiConst.AMAZFIT_BIP5_NAME)) { - return DeviceType.AMAZFITBIP5; - } - } catch (final Exception e) { - LOG.error("unable to check device support", e); - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.AMAZFIT_BIP5_NAME + ".*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbips/AmazfitBipSCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbips/AmazfitBipSCoordinator.java index f880f6515..a66d89599 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbips/AmazfitBipSCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbips/AmazfitBipSCoordinator.java @@ -25,30 +25,21 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +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.impl.GBDeviceCandidate; -import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbips.AmazfitBipSSupport; public class AmazfitBipSCoordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitBipSCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && (name.equalsIgnoreCase("Amazfit Bip S"))) { - return DeviceType.AMAZFITBIPS; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit Bip S", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbips/AmazfitBipSLiteCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbips/AmazfitBipSLiteCoordinator.java index 01cc2106a..3a16bfd99 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbips/AmazfitBipSLiteCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbips/AmazfitBipSLiteCoordinator.java @@ -25,6 +25,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; @@ -35,18 +37,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbips.Am public class AmazfitBipSLiteCoordinator extends AmazfitBipSCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitBipSLiteCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && (name.equalsIgnoreCase("Bip S Lite"))) { - return DeviceType.AMAZFITBIPS_LITE; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Bip S Lite", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbipu/AmazfitBipUCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbipu/AmazfitBipUCoordinator.java index a7d5f5c1b..a0af5cacf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbipu/AmazfitBipUCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbipu/AmazfitBipUCoordinator.java @@ -26,6 +26,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; @@ -38,18 +40,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbipu.Am public class AmazfitBipUCoordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitBipUCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && (name.equalsIgnoreCase("Amazfit Bip U"))) { - return DeviceType.AMAZFITBIPU; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit Bip U", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbipupro/AmazfitBipUProCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbipupro/AmazfitBipUProCoordinator.java index d9ff1e756..4e7b77acf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbipupro/AmazfitBipUProCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbipupro/AmazfitBipUProCoordinator.java @@ -26,6 +26,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; @@ -38,18 +40,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbipupro public class AmazfitBipUProCoordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitBipUProCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && (name.equalsIgnoreCase("Amazfit Bip U Pro"))) { - return DeviceType.AMAZFITBIPUPRO; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit Bip U Pro", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcheetahpro/AmazfitCheetahProCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcheetahpro/AmazfitCheetahProCoordinator.java index 41bd985d7..17e9f8146 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcheetahpro/AmazfitCheetahProCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcheetahpro/AmazfitCheetahProCoordinator.java @@ -24,6 +24,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; @@ -37,19 +39,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitcheetah public class AmazfitCheetahProCoordinator extends Huami2021Coordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitCheetahProCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - try { - final String name = candidate.getName(); - if (name != null && name.startsWith(HuamiConst.AMAZFIT_CHEETAH_PRO_NAME)) { - return DeviceType.AMAZFITCHEETAHPRO; - } - } catch (final Exception e) { - LOG.error("unable to check device support", e); - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.AMAZFIT_CHEETAH_PRO_NAME + ".*"); } @NonNull diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcheetahround/AmazfitCheetahRoundCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcheetahround/AmazfitCheetahRoundCoordinator.java index 1fc3245b2..fa6848199 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcheetahround/AmazfitCheetahRoundCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcheetahround/AmazfitCheetahRoundCoordinator.java @@ -24,6 +24,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; @@ -53,19 +55,9 @@ public class AmazfitCheetahRoundCoordinator extends Huami2021Coordinator { return R.string.devicetype_amazfit_cheetah_round; } - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - try { - final String name = candidate.getName(); - if (name != null && name.startsWith(HuamiConst.AMAZFIT_CHEETAH_ROUND_NAME)) { - return DeviceType.AMAZFITCHEETAHROUND; - } - } catch (final Exception e) { - LOG.error("unable to check device support", e); - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.AMAZFIT_CHEETAH_ROUND_NAME + ".*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcheetahsquare/AmazfitCheetahSquareCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcheetahsquare/AmazfitCheetahSquareCoordinator.java index 09df8c030..3016ffa4b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcheetahsquare/AmazfitCheetahSquareCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcheetahsquare/AmazfitCheetahSquareCoordinator.java @@ -24,6 +24,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; @@ -48,19 +50,9 @@ public class AmazfitCheetahSquareCoordinator extends Huami2021Coordinator { return AmazfitCheetahSquareSupport.class; } - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - try { - final String name = candidate.getName(); - if (name != null && name.startsWith(HuamiConst.AMAZFIT_CHEETAH_SQUARE_NAME)) { - return DeviceType.AMAZFITCHEETAHSQUARE; - } - } catch (final Exception e) { - LOG.error("unable to check device support", e); - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.AMAZFIT_CHEETAH_SQUARE_NAME + ".*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcor/AmazfitCorCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcor/AmazfitCorCoordinator.java index e1ff6e1f1..5c6cc5dce 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcor/AmazfitCorCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcor/AmazfitCorCoordinator.java @@ -25,6 +25,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; @@ -37,18 +39,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitcor.Ama public class AmazfitCorCoordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitCorCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && (name.equalsIgnoreCase("Amazfit Band") || name.equalsIgnoreCase("Amazfit Cor"))) { - return DeviceType.AMAZFITCOR; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit Band|Amazfit Cor", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcor2/AmazfitCor2Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcor2/AmazfitCor2Coordinator.java index 38037cd38..32f2a82f0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcor2/AmazfitCor2Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcor2/AmazfitCor2Coordinator.java @@ -25,6 +25,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; @@ -37,18 +39,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitcor2.Am public class AmazfitCor2Coordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitCor2Coordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && (name.equalsIgnoreCase("Amazfit Band 2") || name.equalsIgnoreCase("Amazfit Cor 2"))) { - return DeviceType.AMAZFITCOR2; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit Band 2|Amazfit Cor 2", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitfalcon/AmazfitFalconCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitfalcon/AmazfitFalconCoordinator.java index 848bcbc1f..6abc0c7a2 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitfalcon/AmazfitFalconCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitfalcon/AmazfitFalconCoordinator.java @@ -24,6 +24,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; @@ -53,19 +55,9 @@ public class AmazfitFalconCoordinator extends Huami2021Coordinator { return R.string.devicetype_amazfit_falcon; } - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - try { - final String name = candidate.getName(); - if (name != null && name.startsWith(HuamiConst.AMAZFIT_FALCON_NAME)) { - return DeviceType.AMAZFITFALCON; - } - } catch (final Exception e) { - LOG.error("unable to check device support", e); - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.AMAZFIT_FALCON_NAME + ".*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr/AmazfitGTRCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr/AmazfitGTRCoordinator.java index 63161c1fb..e0f2470d9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr/AmazfitGTRCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr/AmazfitGTRCoordinator.java @@ -25,6 +25,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; @@ -37,20 +39,10 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitgtr.Ama public class AmazfitGTRCoordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitGTRCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && name.equalsIgnoreCase("Amazfit GTR")) { - return DeviceType.AMAZFITGTR; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit GTR", Pattern.CASE_INSENSITIVE); } - @Override public InstallHandler findInstallHandler(Uri uri, Context context) { AmazfitGTRFWInstallHandler handler = new AmazfitGTRFWInstallHandler(uri, context); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr/AmazfitGTRLiteCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr/AmazfitGTRLiteCoordinator.java index 2d444473c..7d7fa1176 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr/AmazfitGTRLiteCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr/AmazfitGTRLiteCoordinator.java @@ -25,6 +25,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; @@ -37,18 +39,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitgtr.Ama public class AmazfitGTRLiteCoordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitGTRLiteCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && name.equalsIgnoreCase("Amazfit GTR L")) { - return DeviceType.AMAZFITGTR_LITE; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit GTR L", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr2/AmazfitGTR2Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr2/AmazfitGTR2Coordinator.java index c3dd97f1a..cf0be46e4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr2/AmazfitGTR2Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr2/AmazfitGTR2Coordinator.java @@ -25,6 +25,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; @@ -37,18 +39,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitgtr2.Am public class AmazfitGTR2Coordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitGTR2Coordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && name.equalsIgnoreCase("Amazfit GTR 2")) { - return DeviceType.AMAZFITGTR2; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit GTR 2", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr2/AmazfitGTR2eCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr2/AmazfitGTR2eCoordinator.java index 014b8f118..fc95ba722 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr2/AmazfitGTR2eCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr2/AmazfitGTR2eCoordinator.java @@ -25,6 +25,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; @@ -37,18 +39,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitgtr2.Am public class AmazfitGTR2eCoordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitGTR2eCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && name.equalsIgnoreCase("Amazfit GTR 2e")) { - return DeviceType.AMAZFITGTR2E; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit GTR 2e", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr3/AmazfitGTR3Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr3/AmazfitGTR3Coordinator.java index 6ef5c165c..c8598233a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr3/AmazfitGTR3Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr3/AmazfitGTR3Coordinator.java @@ -39,17 +39,17 @@ public class AmazfitGTR3Coordinator extends Huami2021Coordinator { @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { + public boolean supports(final GBDeviceCandidate candidate) { try { final String name = candidate.getName(); if (name != null && name.startsWith(HuamiConst.AMAZFIT_GTR3_NAME) && !name.contains("Pro")) { - return DeviceType.AMAZFITGTR3; + return true; } } catch (final Exception e) { LOG.error("unable to check device support", e); } - return DeviceType.UNKNOWN; + return false; } @NonNull diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr3pro/AmazfitGTR3ProCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr3pro/AmazfitGTR3ProCoordinator.java index 3b81c06f4..0cf410ab1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr3pro/AmazfitGTR3ProCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr3pro/AmazfitGTR3ProCoordinator.java @@ -24,6 +24,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; @@ -37,19 +39,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitgtr3pro public class AmazfitGTR3ProCoordinator extends Huami2021Coordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitGTR3ProCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - try { - final String name = candidate.getName(); - if (name != null && name.startsWith(HuamiConst.AMAZFIT_GTR3_PRO_NAME)) { - return DeviceType.AMAZFITGTR3PRO; - } - } catch (final Exception e) { - LOG.error("unable to check device support", e); - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.AMAZFIT_GTR3_PRO_NAME + ".*"); } @NonNull diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr4/AmazfitGTR4Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr4/AmazfitGTR4Coordinator.java index d6c7382dd..25de3a9cd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr4/AmazfitGTR4Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr4/AmazfitGTR4Coordinator.java @@ -24,6 +24,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; @@ -37,19 +39,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitgtr4.Am public class AmazfitGTR4Coordinator extends Huami2021Coordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitGTR4Coordinator.class); - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - try { - final String name = candidate.getName(); - if (name != null && name.startsWith(HuamiConst.AMAZFIT_GTR4_NAME)) { - return DeviceType.AMAZFITGTR4; - } - } catch (final Exception e) { - LOG.error("unable to check device support", e); - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.AMAZFIT_GTR4_NAME + ".*"); } @NonNull diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtrmini/AmazfitGTRMiniCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtrmini/AmazfitGTRMiniCoordinator.java index b4bf04740..88ab8e84e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtrmini/AmazfitGTRMiniCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtrmini/AmazfitGTRMiniCoordinator.java @@ -24,6 +24,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; @@ -48,19 +50,9 @@ public class AmazfitGTRMiniCoordinator extends Huami2021Coordinator { return R.string.devicetype_amazfit_gtr_mini; } - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - try { - final String name = candidate.getName(); - if (name != null && name.startsWith(HuamiConst.AMAZFIT_GTR_MINI_NAME)) { - return DeviceType.AMAZFITGTRMINI; - } - } catch (final Exception e) { - LOG.error("unable to check device support", e); - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.AMAZFIT_GTR_MINI_NAME + ".*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts/AmazfitGTSCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts/AmazfitGTSCoordinator.java index 7fcc7cad7..7c511b90a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts/AmazfitGTSCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts/AmazfitGTSCoordinator.java @@ -24,6 +24,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; @@ -36,18 +38,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitgts.Ama public class AmazfitGTSCoordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitGTSCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && name.equalsIgnoreCase("Amazfit GTS")) { - return DeviceType.AMAZFITGTS; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit GTS", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts2/AmazfitGTS2Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts2/AmazfitGTS2Coordinator.java index 3e96f7e01..643f1dfd4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts2/AmazfitGTS2Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts2/AmazfitGTS2Coordinator.java @@ -25,6 +25,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; @@ -37,18 +39,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitgts2.Am public class AmazfitGTS2Coordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitGTS2Coordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && name.equalsIgnoreCase("Amazfit GTS 2")) { - return DeviceType.AMAZFITGTS2; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit GTS 2", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts2/AmazfitGTS2MiniCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts2/AmazfitGTS2MiniCoordinator.java index fef5fa556..872f2277d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts2/AmazfitGTS2MiniCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts2/AmazfitGTS2MiniCoordinator.java @@ -25,6 +25,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; @@ -36,18 +38,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitgts2.Am public class AmazfitGTS2MiniCoordinator extends AmazfitGTS2Coordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitGTS2MiniCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && name.equalsIgnoreCase("Amazfit GTS2 mini")) { - return DeviceType.AMAZFITGTS2_MINI; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit GTS2 mini", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts2/AmazfitGTS2eCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts2/AmazfitGTS2eCoordinator.java index efe52ea1a..a76262cda 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts2/AmazfitGTS2eCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts2/AmazfitGTS2eCoordinator.java @@ -25,6 +25,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; @@ -37,18 +39,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitgts2.Am public class AmazfitGTS2eCoordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitGTS2eCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && name.equalsIgnoreCase("Amazfit GTS 2e")) { - return DeviceType.AMAZFITGTS2E; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit GTS 2e", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts3/AmazfitGTS3Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts3/AmazfitGTS3Coordinator.java index 4e66a6672..b1408b035 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts3/AmazfitGTS3Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts3/AmazfitGTS3Coordinator.java @@ -24,6 +24,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; @@ -37,19 +39,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitgts3.Am public class AmazfitGTS3Coordinator extends Huami2021Coordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitGTS3Coordinator.class); - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - try { - final String name = candidate.getName(); - if (name != null && name.startsWith(HuamiConst.AMAZFIT_GTS3_NAME)) { - return DeviceType.AMAZFITGTS3; - } - } catch (final Exception e) { - LOG.error("unable to check device support", e); - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.AMAZFIT_GTS3_NAME + ".*"); } @NonNull diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts4/AmazfitGTS4Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts4/AmazfitGTS4Coordinator.java index 6663e6a9f..347b5ac4f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts4/AmazfitGTS4Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts4/AmazfitGTS4Coordinator.java @@ -39,17 +39,17 @@ public class AmazfitGTS4Coordinator extends Huami2021Coordinator { @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { + public boolean supports(final GBDeviceCandidate candidate) { try { final String name = candidate.getName(); if (name != null && name.startsWith(HuamiConst.AMAZFIT_GTS4_NAME) && !name.contains("Mini")) { - return DeviceType.AMAZFITGTS4; + return true; } } catch (final Exception e) { LOG.error("unable to check device support", e); } - return DeviceType.UNKNOWN; + return false; } @NonNull diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts4mini/AmazfitGTS4MiniCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts4mini/AmazfitGTS4MiniCoordinator.java index b22f38f9b..2c11e2d52 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts4mini/AmazfitGTS4MiniCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts4mini/AmazfitGTS4MiniCoordinator.java @@ -24,6 +24,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; @@ -37,19 +39,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitgts4min public class AmazfitGTS4MiniCoordinator extends Huami2021Coordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitGTS4MiniCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - try { - final String name = candidate.getName(); - if (name != null && name.startsWith(HuamiConst.AMAZFIT_GTS4_MINI_NAME)) { - return DeviceType.AMAZFITGTS4MINI; - } - } catch (final Exception e) { - LOG.error("unable to check device support", e); - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.AMAZFIT_GTS4_MINI_NAME + ".*"); } @NonNull diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitneo/AmazfitNeoCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitneo/AmazfitNeoCoordinator.java index 4108c2716..10e502b55 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitneo/AmazfitNeoCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitneo/AmazfitNeoCoordinator.java @@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory; import java.util.Arrays; import java.util.List; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.capabilities.HeartRateCapability; @@ -41,19 +42,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitneo.Ama public class AmazfitNeoCoordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitNeoCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.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; - + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.AMAZFIT_NEO_NAME, Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitpop/AmazfitPopCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitpop/AmazfitPopCoordinator.java index c1fae8626..1d5459640 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitpop/AmazfitPopCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitpop/AmazfitPopCoordinator.java @@ -24,6 +24,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbipu.AmazfitBipUCoordinator; @@ -35,18 +37,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitpop.Ama public class AmazfitPopCoordinator extends AmazfitBipUCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitPopCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && (name.equalsIgnoreCase("Amazfit Pop"))) { - return DeviceType.AMAZFITPOP; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit Pop", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitpoppro/AmazfitPopProCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitpoppro/AmazfitPopProCoordinator.java index 24ab47517..48ad8f02c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitpoppro/AmazfitPopProCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitpoppro/AmazfitPopProCoordinator.java @@ -24,6 +24,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbipupro.AmazfitBipUProCoordinator; @@ -35,18 +37,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitpoppro. public class AmazfitPopProCoordinator extends AmazfitBipUProCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitPopProCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && (name.equalsIgnoreCase("Amazfit Pop Pro"))) { - return DeviceType.AMAZFITPOPPRO; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit Pop Pro", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfittrex/AmazfitTRexCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfittrex/AmazfitTRexCoordinator.java index a896fb447..579685a28 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfittrex/AmazfitTRexCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfittrex/AmazfitTRexCoordinator.java @@ -25,6 +25,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; @@ -37,18 +39,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfittrex.Am public class AmazfitTRexCoordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitTRexCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && name.equalsIgnoreCase("Amazfit T-Rex")) { - return DeviceType.AMAZFITTREX; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit T-Rex", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfittrex2/AmazfitTRex2Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfittrex2/AmazfitTRex2Coordinator.java index ec4e600a3..fc6981046 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfittrex2/AmazfitTRex2Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfittrex2/AmazfitTRex2Coordinator.java @@ -24,6 +24,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; @@ -37,19 +39,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfittrex2.A public class AmazfitTRex2Coordinator extends Huami2021Coordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitTRex2Coordinator.class); - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - try { - final String name = candidate.getName(); - if (name != null && name.startsWith(HuamiConst.AMAZFIT_TREX_2_NAME)) { - return DeviceType.AMAZFITTREX2; - } - } catch (final Exception e) { - LOG.error("unable to check device support", e); - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.AMAZFIT_TREX_2_NAME + ".*"); } @NonNull diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfittrexpro/AmazfitTRexProCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfittrexpro/AmazfitTRexProCoordinator.java index d681f703b..baf7231fa 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfittrexpro/AmazfitTRexProCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfittrexpro/AmazfitTRexProCoordinator.java @@ -25,6 +25,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; @@ -37,18 +39,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfittrexpro public class AmazfitTRexProCoordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitTRexProCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && name.equalsIgnoreCase("Amazfit T-Rex Pro")) { - return DeviceType.AMAZFITTREXPRO; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit T-Rex Pro", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfittrexultra/AmazfitTRexUltraCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfittrexultra/AmazfitTRexUltraCoordinator.java index 9372ab92f..fe34e0192 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfittrexultra/AmazfitTRexUltraCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfittrexultra/AmazfitTRexUltraCoordinator.java @@ -24,6 +24,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; @@ -53,19 +55,9 @@ public class AmazfitTRexUltraCoordinator extends Huami2021Coordinator { return R.string.devicetype_amazfit_trex_ultra; } - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - try { - final String name = candidate.getName(); - if (name != null && name.startsWith(HuamiConst.AMAZFIT_TREX_ULTRA)) { - return DeviceType.AMAZFITTREXULTRA; - } - } catch (final Exception e) { - LOG.error("unable to check device support", e); - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.AMAZFIT_TREX_ULTRA + ".*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitvergel/AmazfitVergeLCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitvergel/AmazfitVergeLCoordinator.java index a69d47a43..c8745b63b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitvergel/AmazfitVergeLCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitvergel/AmazfitVergeLCoordinator.java @@ -16,7 +16,6 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitvergel; -import android.bluetooth.BluetoothDevice; import android.content.Context; import android.net.Uri; @@ -25,6 +24,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; @@ -37,18 +38,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitvergel. public class AmazfitVergeLCoordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitVergeLCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && name.equalsIgnoreCase("Amazfit Verge L")) { - return DeviceType.AMAZFITVERGEL; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Amazfit Verge L", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitx/AmazfitXCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitx/AmazfitXCoordinator.java index 32e98c0a6..739d25445 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitx/AmazfitXCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitx/AmazfitXCoordinator.java @@ -25,11 +25,12 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + 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.devices.huami.amazfitx.AmazfitXFWInstallHandler; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; @@ -39,22 +40,11 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitx.Amazf public class AmazfitXCoordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitXCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && name.equalsIgnoreCase(HuamiConst.AMAZFIT_X)) { - return DeviceType.AMAZFITX; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; - + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.AMAZFIT_X, Pattern.CASE_INSENSITIVE); } - @Override public InstallHandler findInstallHandler(Uri uri, Context context) { // TOOD Need to be checked first diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2Coordinator.java index 0af6558af..75113860b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2Coordinator.java @@ -26,6 +26,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.EnumSet; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; @@ -41,21 +42,10 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.MiBand public class MiBand2Coordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(MiBand2Coordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && name.equalsIgnoreCase(HuamiConst.MI_BAND2_NAME)) { - return DeviceType.MIBAND2; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; - + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.MI_BAND2_NAME, Pattern.CASE_INSENSITIVE); } - @Override public InstallHandler findInstallHandler(Uri uri, Context context) { MiBand2FWInstallHandler handler = new MiBand2FWInstallHandler(uri, context); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2HRXCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2HRXCoordinator.java index f1775bae8..c29186caf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2HRXCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2HRXCoordinator.java @@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory; import androidx.annotation.NonNull; import java.util.EnumSet; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; @@ -41,18 +42,12 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.MiBand public class MiBand2HRXCoordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(MiBand2HRXCoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (HuamiConst.MI_BAND2_NAME_HRX.equalsIgnoreCase(name) || "Mi Band 2i".equalsIgnoreCase(name)) { - return DeviceType.MIBAND2_HRX; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile( + HuamiConst.MI_BAND2_NAME_HRX + "|Mi Band 2i", + Pattern.CASE_INSENSITIVE + ); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband3/MiBand3Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband3/MiBand3Coordinator.java index 4d49a8b76..48364887f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband3/MiBand3Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband3/MiBand3Coordinator.java @@ -26,6 +26,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Date; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; @@ -43,19 +44,12 @@ import nodomain.freeyourgadget.gadgetbridge.util.Prefs; public class MiBand3Coordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(MiBand3Coordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && (name.equalsIgnoreCase(HuamiConst.MI_BAND3_NAME) || name.equalsIgnoreCase(HuamiConst.MI_BAND3_NAME_2))) { - return DeviceType.MIBAND3; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; - + protected Pattern getSupportedDeviceName() { + return Pattern.compile( + HuamiConst.MI_BAND3_NAME + "|" + HuamiConst.MI_BAND3_NAME_2, + Pattern.CASE_INSENSITIVE + ); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband4/MiBand4Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband4/MiBand4Coordinator.java index 9c994dfd8..50bbe0530 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband4/MiBand4Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband4/MiBand4Coordinator.java @@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory; import java.util.Arrays; import java.util.List; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.capabilities.HeartRateCapability; @@ -43,22 +44,11 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband4.MiBand public class MiBand4Coordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(MiBand4Coordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && name.equalsIgnoreCase(HuamiConst.MI_BAND4_NAME)) { - return DeviceType.MIBAND4; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; - + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.MI_BAND4_NAME, Pattern.CASE_INSENSITIVE); } - @Override public InstallHandler findInstallHandler(Uri uri, Context context) { MiBand4FWInstallHandler handler = new MiBand4FWInstallHandler(uri, context); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband5/MiBand5Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband5/MiBand5Coordinator.java index 680340589..5c5ebc85a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband5/MiBand5Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband5/MiBand5Coordinator.java @@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory; import java.util.Arrays; import java.util.List; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.capabilities.HeartRateCapability; @@ -42,19 +43,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband5.MiBand public class MiBand5Coordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(MiBand5Coordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && name.equalsIgnoreCase(HuamiConst.MI_BAND5_NAME)) { - return DeviceType.MIBAND5; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; - + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.MI_BAND5_NAME, Pattern.CASE_INSENSITIVE); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband6/MiBand6Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband6/MiBand6Coordinator.java index f3553eaa1..bd2c6d23c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband6/MiBand6Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband6/MiBand6Coordinator.java @@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory; import java.util.Arrays; import java.util.List; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.capabilities.HeartRateCapability; @@ -25,18 +26,10 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband6.MiBand public class MiBand6Coordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(MiBand6Coordinator.class); - @NonNull + @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.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; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.MI_BAND6_NAME, Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband7/MiBand7Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband7/MiBand7Coordinator.java index 9f861b49f..7f4d18279 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband7/MiBand7Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband7/MiBand7Coordinator.java @@ -24,6 +24,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; @@ -37,19 +39,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband7.MiBand public class MiBand7Coordinator extends Huami2021Coordinator { private static final Logger LOG = LoggerFactory.getLogger(MiBand7Coordinator.class); - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - try { - final String name = candidate.getName(); - if (name != null && name.startsWith(HuamiConst.XIAOMI_SMART_BAND7_NAME)) { - return DeviceType.MIBAND7; - } - } catch (final Exception e) { - LOG.error("unable to check device support", e); - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(HuamiConst.XIAOMI_SMART_BAND7_NAME + ".*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/zeppe/ZeppECoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/zeppe/ZeppECoordinator.java index 9d7677038..f0a38483d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/zeppe/ZeppECoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/zeppe/ZeppECoordinator.java @@ -25,6 +25,8 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; @@ -37,18 +39,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppe.ZeppESup public class ZeppECoordinator extends HuamiCoordinator { private static final Logger LOG = LoggerFactory.getLogger(ZeppECoordinator.class); - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && name.equalsIgnoreCase("Zepp E")) { - return DeviceType.ZEPP_E; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Zepp E", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/id115/ID115Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/id115/ID115Coordinator.java index 49cb6a2a8..0ef30d266 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/id115/ID115Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/id115/ID115Coordinator.java @@ -17,12 +17,10 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.id115; -import android.annotation.TargetApi; import android.app.Activity; import android.bluetooth.le.ScanFilter; import android.content.Context; import android.net.Uri; -import android.os.Build; import android.os.ParcelUuid; import java.util.Collection; @@ -59,11 +57,11 @@ public class ID115Coordinator extends AbstractBLEDeviceCoordinator { @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { + public boolean supports(GBDeviceCandidate candidate) { if (candidate.supportsService(ID115Constants.UUID_SERVICE_ID115)) { - return DeviceType.ID115; + return true; } - return DeviceType.UNKNOWN; + return false; } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/itag/ITagCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/itag/ITagCoordinator.java index 0ce3cd077..166e74603 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/itag/ITagCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/itag/ITagCoordinator.java @@ -17,17 +17,16 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.itag; -import android.annotation.TargetApi; import android.app.Activity; import android.bluetooth.le.ScanFilter; import android.content.Context; import android.net.Uri; -import android.os.Build; import androidx.annotation.NonNull; import java.util.Collection; import java.util.Collections; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator; @@ -44,13 +43,8 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.itag.ITagSupport; public class ITagCoordinator extends AbstractBLEDeviceCoordinator { @Override - @NonNull - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - if (name != null && name.toLowerCase().startsWith("itag")) { // All four: iTAG, iTag, ITAG and ITag exist - return DeviceType.ITAG; - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("itag.*", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/jyou/BFH16DeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/jyou/BFH16DeviceCoordinator.java index 55b8d6134..f175928b4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/jyou/BFH16DeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/jyou/BFH16DeviceCoordinator.java @@ -28,6 +28,7 @@ import org.slf4j.LoggerFactory; import java.util.Collection; import java.util.Collections; +import java.util.regex.Pattern; import androidx.annotation.NonNull; import nodomain.freeyourgadget.gadgetbridge.GBException; @@ -67,19 +68,9 @@ public class BFH16DeviceCoordinator extends AbstractBLEDeviceCoordinator return Collections.singletonList(filter); } - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - - String name = candidate.getName(); - if (name != null) { - if (name.startsWith("BFH-16")) { - return DeviceType.BFH16; - } - } - - return DeviceType.UNKNOWN; - + protected Pattern getSupportedDeviceName() { + return Pattern.compile("BFH-16.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/jyou/TeclastH30/TeclastH30Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/jyou/TeclastH30/TeclastH30Coordinator.java index 505515d0d..eab3455a7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/jyou/TeclastH30/TeclastH30Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/jyou/TeclastH30/TeclastH30Coordinator.java @@ -17,12 +17,10 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.jyou.TeclastH30; -import android.annotation.TargetApi; import android.app.Activity; import android.bluetooth.le.ScanFilter; import android.content.Context; import android.net.Uri; -import android.os.Build; import android.os.ParcelUuid; import org.slf4j.Logger; @@ -53,9 +51,6 @@ public class TeclastH30Coordinator extends AbstractBLEDeviceCoordinator { protected static final Logger LOG = LoggerFactory.getLogger(TeclastH30Coordinator.class); - // e.g. H3-B20F - private Pattern deviceNamePattern = Pattern.compile("^H[13]-[ABCDEF0123456789]{4}$"); - @NonNull @Override public Collection createBLEScanFilters() { @@ -66,22 +61,17 @@ public class TeclastH30Coordinator extends AbstractBLEDeviceCoordinator { @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { + public boolean supports(GBDeviceCandidate candidate) { if (candidate.supportsService(JYouConstants.UUID_SERVICE_JYOU)) { - return DeviceType.TECLASTH30; + return true; } - String name = candidate.getName(); - if (name != null) { - if (name.startsWith("TECLAST_H30") || name.startsWith("TECLAST_H10")) { - return DeviceType.TECLASTH30; - } - Matcher deviceNameMatcher = deviceNamePattern.matcher(name); - if (deviceNameMatcher.matches()) { - return DeviceType.TECLASTH30; - } - } - return DeviceType.UNKNOWN; + return super.supports(candidate); + } + + @Override + protected Pattern getSupportedDeviceName() { + return Pattern.compile("TECLAST_H[13]0.*|H[13]-[ABCDEF0123456789]{4}"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/jyou/y5/Y5Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/jyou/y5/Y5Coordinator.java index 972a148d9..808e199eb 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/jyou/y5/Y5Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/jyou/y5/Y5Coordinator.java @@ -23,6 +23,8 @@ import android.net.Uri; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import java.util.regex.Pattern; + import de.greenrobot.dao.query.QueryBuilder; import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; @@ -48,20 +50,9 @@ public class Y5Coordinator extends AbstractBLEDeviceCoordinator { qb.where(JYouActivitySampleDao.Properties.DeviceId.eq(deviceId)).buildDelete().executeDeleteWithoutDetachingEntities(); } - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null) { - if (name.contains("Y5")) { - return DeviceType.Y5; - } - } - } catch (Exception ex) { - ex.getLocalizedMessage(); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(".*Y5.*"); } @Nullable diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lefun/BohemicSmartBraceletDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lefun/BohemicSmartBraceletDeviceCoordinator.java index a98de65cf..caea3e6f3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lefun/BohemicSmartBraceletDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lefun/BohemicSmartBraceletDeviceCoordinator.java @@ -19,20 +19,17 @@ package nodomain.freeyourgadget.gadgetbridge.devices.lefun; import androidx.annotation.NonNull; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; public class BohemicSmartBraceletDeviceCoordinator extends LefunDeviceCoordinator { - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - if (".bohemic".equals(candidate.getName())) { - return DeviceType.BOHEMIC_SMART_BRACELET; - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("\\.bohemic"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lefun/LefunDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lefun/LefunDeviceCoordinator.java index 06c82ba69..d5f8f474c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lefun/LefunDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lefun/LefunDeviceCoordinator.java @@ -58,7 +58,7 @@ public class LefunDeviceCoordinator extends AbstractBLEDeviceCoordinator { @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { + public boolean supports(GBDeviceCandidate candidate) { // There's a bunch of other names other than "Lefun", but let's just focus on one for now. if (ADVERTISEMENT_NAME.equals(candidate.getName())) { // The device does not advertise service UUIDs, so can't check whether it supports @@ -67,11 +67,11 @@ public class LefunDeviceCoordinator extends AbstractBLEDeviceCoordinator { // manufacturer specific data, which consists of the device's MAC address and said // string. But we're not being given it, so *shrug*. if (candidate.getServiceUuids().length == 0) { - return DeviceType.LEFUN; + return true; } } - return DeviceType.UNKNOWN; + return false; } @Nullable diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lenovo/watchxplus/WatchXPlusDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lenovo/watchxplus/WatchXPlusDeviceCoordinator.java index 4ee6efacf..e58d80aad 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lenovo/watchxplus/WatchXPlusDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lenovo/watchxplus/WatchXPlusDeviceCoordinator.java @@ -18,13 +18,11 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.lenovo.watchxplus; -import android.annotation.TargetApi; import android.app.Activity; import android.bluetooth.le.ScanFilter; import android.content.Context; import android.content.SharedPreferences; import android.net.Uri; -import android.os.Build; import android.os.ParcelUuid; import androidx.annotation.NonNull; @@ -90,21 +88,21 @@ public class WatchXPlusDeviceCoordinator extends AbstractBLEDeviceCoordinator { @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { + public boolean supports(GBDeviceCandidate candidate) { String macAddress = candidate.getMacAddress().toUpperCase(); String deviceName = candidate.getName().toUpperCase(); if (candidate.supportsService(WatchXPlusConstants.UUID_SERVICE_WATCHXPLUS)) { - return DeviceType.WATCHXPLUS; + return true; } else if (macAddress.startsWith("DC:41:E5")) { - return DeviceType.WATCHXPLUS; + return true; } else if (deviceName.equalsIgnoreCase("WATCH XPLUS")) { - return DeviceType.WATCHXPLUS; + return true; // add initial support for Watch X non-plus (forces Watch X to be recognized as Watch XPlus) // Watch X non-plus have same MAC address as Watch 9 (starts with "1C:87:79") } else if (deviceName.equalsIgnoreCase("WATCH X")) { - return DeviceType.WATCHXPLUS; + return true; } - return DeviceType.UNKNOWN; + return false; } @Nullable diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/liveview/LiveviewCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/liveview/LiveviewCoordinator.java index 9aa081c65..f57461185 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/liveview/LiveviewCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/liveview/LiveviewCoordinator.java @@ -22,6 +22,9 @@ import android.content.Context; import android.net.Uri; import androidx.annotation.NonNull; + +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLClassicDeviceCoordinator; @@ -37,14 +40,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.liveview.LiveviewSupport; public class LiveviewCoordinator extends AbstractBLClassicDeviceCoordinator { - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - if (name != null && name.startsWith("LiveView")) { - return DeviceType.LIVEVIEW; - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("LiveView.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/makibeshr3/MakibesHR3Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/makibeshr3/MakibesHR3Coordinator.java index 3476af12e..ce1a890fc 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/makibeshr3/MakibesHR3Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/makibeshr3/MakibesHR3Coordinator.java @@ -22,6 +22,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.List; +import java.util.regex.Pattern; import android.app.Activity; import android.content.Context; @@ -35,7 +36,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import de.greenrobot.dao.query.QueryBuilder; -import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst; @@ -150,23 +150,9 @@ public class MakibesHR3Coordinator extends AbstractBLEDeviceCoordinator { } } - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - - List deviceNames = new ArrayList(){{ - add("Y808"); // Chinese version - add("MAKIBES HR3"); // English version - }}; - - if (name != null) { - if (deviceNames.contains(name)) { - return DeviceType.MAKIBESHR3; - } - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Y808|MAKIBES HR3"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandCoordinator.java index 6b04913ac..f8147cb45 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandCoordinator.java @@ -17,13 +17,11 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.miband; -import android.annotation.TargetApi; import android.app.Activity; import android.bluetooth.BluetoothDevice; import android.bluetooth.le.ScanFilter; import android.content.Context; import android.net.Uri; -import android.os.Build; import android.os.ParcelUuid; import androidx.annotation.DrawableRes; @@ -76,15 +74,15 @@ public class MiBandCoordinator extends AbstractBLEDeviceCoordinator { @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { + public boolean supports(GBDeviceCandidate candidate) { String macAddress = candidate.getMacAddress().toUpperCase(); if (macAddress.startsWith(MiBandService.MAC_ADDRESS_FILTER_1_1A) || macAddress.startsWith(MiBandService.MAC_ADDRESS_FILTER_1S)) { - return DeviceType.MIBAND; + return true; } if (candidate.supportsService(MiBandService.UUID_SERVICE_MIBAND_SERVICE) && !candidate.supportsService(MiBandService.UUID_SERVICE_MIBAND2_SERVICE)) { - return DeviceType.MIBAND; + return true; } // and a heuristic try { @@ -92,13 +90,13 @@ public class MiBandCoordinator extends AbstractBLEDeviceCoordinator { if (isHealthWearable(device)) { String name = candidate.getName(); if (name != null && name.toUpperCase().startsWith(MiBandConst.MI_GENERAL_NAME_PREFIX.toUpperCase())) { - return DeviceType.MIBAND; + return true; } } } catch (Exception ex) { LOG.error("unable to check device support", ex); } - return DeviceType.UNKNOWN; + return false; } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/mijia_lywsd02/MijiaLywsd02Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/mijia_lywsd02/MijiaLywsd02Coordinator.java index ebbf1df8f..cad6d1c1f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/mijia_lywsd02/MijiaLywsd02Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/mijia_lywsd02/MijiaLywsd02Coordinator.java @@ -23,6 +23,8 @@ import android.net.Uri; import androidx.annotation.NonNull; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; @@ -37,14 +39,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.mijia_lywsd02.MijiaLywsd02Support; public class MijiaLywsd02Coordinator extends AbstractBLEDeviceCoordinator { - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - if (name != null && (name.equals("LYWSD02") || name.equals("LYWSD02MMC"))) { - return DeviceType.MIJIA_LYWSD02; - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("LYWSD02|LYWSD02MMC"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miscale2/MiScale2DeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miscale2/MiScale2DeviceCoordinator.java index 8e0bd6d34..922daba70 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miscale2/MiScale2DeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miscale2/MiScale2DeviceCoordinator.java @@ -17,12 +17,10 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.miscale2; -import android.annotation.TargetApi; import android.app.Activity; import android.bluetooth.le.ScanFilter; import android.content.Context; import android.net.Uri; -import android.os.Build; import android.os.ParcelUuid; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -32,6 +30,7 @@ import org.slf4j.LoggerFactory; import java.util.Collection; import java.util.Collections; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; @@ -56,18 +55,9 @@ public class MiScale2DeviceCoordinator extends AbstractBLEDeviceCoordinator { } - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && name.equalsIgnoreCase("MIBCS")) { - return DeviceType.MISCALE2; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("MIBCS", Pattern.CASE_INSENSITIVE); } @NonNull diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/no1f1/No1F1Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/no1f1/No1F1Coordinator.java index 0788c0523..119fb57d5 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/no1f1/No1F1Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/no1f1/No1F1Coordinator.java @@ -17,16 +17,15 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.no1f1; -import android.annotation.TargetApi; import android.app.Activity; import android.bluetooth.le.ScanFilter; import android.content.Context; import android.net.Uri; -import android.os.Build; import android.os.ParcelUuid; import java.util.Collection; import java.util.Collections; +import java.util.regex.Pattern; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -56,17 +55,10 @@ public class No1F1Coordinator extends AbstractBLEDeviceCoordinator { return Collections.singletonList(filter); } - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - if (name != null && (name.startsWith("X-RUN") || name.startsWith("MH30"))) { - return DeviceType.NO1F1; - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("X-RUN.*|MH30.*"); } - @Override public int getBondingStyle() { return BONDING_STYLE_NONE; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/nothing/Ear1Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/nothing/Ear1Coordinator.java index e4b1a94ba..678538951 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/nothing/Ear1Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/nothing/Ear1Coordinator.java @@ -7,6 +7,8 @@ import android.net.Uri; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLClassicDeviceCoordinator; @@ -23,13 +25,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.nothing.Ear1Support; public class Ear1Coordinator extends AbstractBLClassicDeviceCoordinator { - - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - if(candidate.getName().equals("Nothing ear (1)")) - return DeviceType.NOTHING_EAR1; - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Nothing ear (1)", Pattern.LITERAL); } @Nullable diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/nut/NutCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/nut/NutCoordinator.java index 4c742ea96..9b42fff76 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/nut/NutCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/nut/NutCoordinator.java @@ -17,17 +17,16 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.nut; -import android.annotation.TargetApi; import android.app.Activity; import android.bluetooth.le.ScanFilter; import android.content.Context; import android.net.Uri; -import android.os.Build; import androidx.annotation.NonNull; import java.util.Collection; import java.util.Collections; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator; @@ -44,13 +43,8 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.nut.NutSupport; public class NutCoordinator extends AbstractBLEDeviceCoordinator { @Override - @NonNull - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - if (name != null && name.toLowerCase().startsWith("nut")) { - return DeviceType.NUTMINI; - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("nut.*", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleCoordinator.java index d68118a62..4c4493a21 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleCoordinator.java @@ -28,6 +28,7 @@ import androidx.annotation.StringRes; import java.io.File; import java.io.IOException; import java.util.List; +import java.util.regex.Pattern; import de.greenrobot.dao.query.QueryBuilder; import nodomain.freeyourgadget.gadgetbridge.GBApplication; @@ -56,14 +57,9 @@ public class PebbleCoordinator extends AbstractBLClassicDeviceCoordinator { public PebbleCoordinator() { } - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - if (name != null && name.startsWith("Pebble")) { - return DeviceType.PEBBLE; - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Pebble.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pinetime/PineTimeJFCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pinetime/PineTimeJFCoordinator.java index 1541d600c..716795d51 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pinetime/PineTimeJFCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pinetime/PineTimeJFCoordinator.java @@ -23,6 +23,8 @@ import android.net.Uri; import androidx.annotation.NonNull; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; @@ -37,14 +39,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.pinetime.PineTimeJFSupport; public class PineTimeJFCoordinator extends AbstractBLEDeviceCoordinator { - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - if (name != null && (name.startsWith("Pinetime-JF") || name.startsWith("InfiniTime"))) { - return DeviceType.PINETIME_JF; - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Pinetime-JF.*|InfiniTime.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qc35/QC35Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qc35/QC35Coordinator.java index d7b4beddb..27877bf21 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qc35/QC35Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qc35/QC35Coordinator.java @@ -23,6 +23,8 @@ import android.net.Uri; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLClassicDeviceCoordinator; @@ -43,13 +45,9 @@ public class QC35Coordinator extends AbstractBLClassicDeviceCoordinator { } - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - if (candidate.getName().startsWith("Bose QC 35")) { - return DeviceType.BOSE_QC35; - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Bose QC 35.*"); } @Nullable diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridCoordinator.java index fde35d0bf..99a7a0145 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridCoordinator.java @@ -17,12 +17,10 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.qhybrid; -import android.annotation.TargetApi; import android.app.Activity; import android.bluetooth.le.ScanFilter; import android.content.Context; import android.net.Uri; -import android.os.Build; import android.os.ParcelUuid; import androidx.annotation.NonNull; @@ -37,8 +35,6 @@ import java.io.IOException; import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBException; @@ -63,13 +59,13 @@ public class QHybridCoordinator extends AbstractBLEDeviceCoordinator { @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { + public boolean supports(GBDeviceCandidate candidate) { for(ParcelUuid uuid : candidate.getServiceUuids()){ if(uuid.getUuid().toString().equals("3dda0001-957f-7d4a-34a6-74696673696d")){ - return DeviceType.FOSSILQHYBRID; + return true; } } - return DeviceType.UNKNOWN; + return false; } @NonNull diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/roidmi/Roidmi1Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/roidmi/Roidmi1Coordinator.java index bf20ecd5b..cc954973c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/roidmi/Roidmi1Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/roidmi/Roidmi1Coordinator.java @@ -33,18 +33,18 @@ public class Roidmi1Coordinator extends RoidmiCoordinator { @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { + public boolean supports(final GBDeviceCandidate candidate) { try { final String name = candidate.getName(); if (name != null && name.contains("睿米车载蓝牙播放器")) { - return DeviceType.ROIDMI; + return true; } } catch (final Exception ex) { LOG.error("unable to check device support", ex); } - return DeviceType.UNKNOWN; + return false; } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/roidmi/Roidmi3Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/roidmi/Roidmi3Coordinator.java index 9aa590465..972d441ce 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/roidmi/Roidmi3Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/roidmi/Roidmi3Coordinator.java @@ -33,22 +33,22 @@ public class Roidmi3Coordinator extends RoidmiCoordinator { @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { + public boolean supports(final GBDeviceCandidate candidate) { try { final String name = candidate.getName(); if (name == null) { - return DeviceType.UNKNOWN; + return false; } if (name.contains("Roidmi Music Blue C") || name.contains("Roidmi C BLE") || name.contains("Mojietu Music Blue C")) { - return DeviceType.ROIDMI3; + return true; } } catch (Exception ex) { LOG.error("unable to check device support", ex); } - return DeviceType.UNKNOWN; + return false; } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/smaq2oss/SMAQ2OSSCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/smaq2oss/SMAQ2OSSCoordinator.java index e7547e5dc..bdb79902f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/smaq2oss/SMAQ2OSSCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/smaq2oss/SMAQ2OSSCoordinator.java @@ -14,6 +14,7 @@ import org.slf4j.LoggerFactory; import java.util.Collection; import java.util.Collections; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; @@ -43,19 +44,9 @@ public class SMAQ2OSSCoordinator extends AbstractBLEDeviceCoordinator { protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException { } - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - // TODO still match for "SMA-Q2-OSS" because of backward firmware compatibility - remove eventually - if (name != null && (name.startsWith("SMAQ2-") || name.equalsIgnoreCase("SMA-Q2-OSS"))) { - return DeviceType.SMAQ2OSS; - } - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("SMAQ2-.*|SMA-Q2-OSS", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/soflow/SoFlowCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/soflow/SoFlowCoordinator.java index 14db5b76f..da456c33a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/soflow/SoFlowCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/soflow/SoFlowCoordinator.java @@ -22,6 +22,8 @@ import android.net.Uri; import androidx.annotation.NonNull; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; @@ -36,14 +38,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.soflow.SoFlowSupport; public class SoFlowCoordinator extends AbstractBLEDeviceCoordinator { - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - if (name != null && name.startsWith("SoFlow-")) { - return DeviceType.SOFLOW_SO6; - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("SoFlow-.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyLinkBudsSCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyLinkBudsSCoordinator.java index f65a020c8..f95d9392e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyLinkBudsSCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyLinkBudsSCoordinator.java @@ -20,6 +20,7 @@ import androidx.annotation.NonNull; import java.util.Arrays; import java.util.List; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCapabilities; @@ -28,14 +29,9 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; public class SonyLinkBudsSCoordinator extends SonyHeadphonesCoordinator { - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - if (candidate.getName().contains("LinkBuds S")) { - return DeviceType.SONY_LINKBUDS_S; - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(".*LinkBuds S.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWF1000XM3Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWF1000XM3Coordinator.java index edad860af..6c0f618db 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWF1000XM3Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWF1000XM3Coordinator.java @@ -20,6 +20,7 @@ import androidx.annotation.NonNull; import java.util.Arrays; import java.util.List; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCapabilities; @@ -29,15 +30,9 @@ import nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; public class SonyWF1000XM3Coordinator extends SonyHeadphonesCoordinator { - - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - if (candidate.getName().contains("WF-1000XM3")) { - return DeviceType.SONY_WF_1000XM3; - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(".*WF-1000XM3.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWF1000XM4Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWF1000XM4Coordinator.java index 47d7c94c5..f07789c72 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWF1000XM4Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWF1000XM4Coordinator.java @@ -20,6 +20,7 @@ import androidx.annotation.NonNull; import java.util.Arrays; import java.util.List; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCapabilities; @@ -29,15 +30,9 @@ import nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; public class SonyWF1000XM4Coordinator extends SonyHeadphonesCoordinator { - - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - if (candidate.getName().contains("WF-1000XM4")) { - return DeviceType.SONY_WF_1000XM4; - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(".*WF-1000XM4.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWF1000XM5Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWF1000XM5Coordinator.java index 23d757408..6c6d8a719 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWF1000XM5Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWF1000XM5Coordinator.java @@ -20,6 +20,7 @@ import androidx.annotation.NonNull; import java.util.Arrays; import java.util.List; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCapabilities; @@ -29,15 +30,9 @@ import nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; public class SonyWF1000XM5Coordinator extends SonyHeadphonesCoordinator { - - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - if (candidate.getName().contains("WF-1000XM5")) { - return DeviceType.SONY_WF_1000XM5; - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(".*WF-1000XM5.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWFSP800NCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWFSP800NCoordinator.java index 1b543cf8f..4b6d9dc11 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWFSP800NCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWFSP800NCoordinator.java @@ -20,6 +20,7 @@ import androidx.annotation.NonNull; import java.util.Arrays; import java.util.List; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCapabilities; @@ -29,14 +30,9 @@ import nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; public class SonyWFSP800NCoordinator extends SonyHeadphonesCoordinator { - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - if (candidate.getName().contains("WF-SP800N")) { - return DeviceType.SONY_WF_SP800N; - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(".*WF-SP800N.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWH1000XM2Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWH1000XM2Coordinator.java index a0f1f2f67..27c99b958 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWH1000XM2Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWH1000XM2Coordinator.java @@ -20,6 +20,7 @@ import androidx.annotation.NonNull; import java.util.Arrays; import java.util.List; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCapabilities; @@ -28,14 +29,9 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; public class SonyWH1000XM2Coordinator extends SonyHeadphonesCoordinator { - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - if (candidate.getName().contains("WH-1000XM2")) { - return DeviceType.SONY_WH_1000XM2; - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(".*WH-1000XM2.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWH1000XM3Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWH1000XM3Coordinator.java index a76a41b14..8220dd9bf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWH1000XM3Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWH1000XM3Coordinator.java @@ -20,6 +20,7 @@ import androidx.annotation.NonNull; import java.util.Arrays; import java.util.List; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCapabilities; @@ -28,16 +29,10 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; public class SonyWH1000XM3Coordinator extends SonyHeadphonesCoordinator { - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - if (candidate.getName().contains("WH-1000XM3")) { - return DeviceType.SONY_WH_1000XM3; - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(".*WH-1000XM3.*"); } - @Override public int getDeviceNameResource() { return R.string.devicetype_sony_wh_1000xm3; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWH1000XM4Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWH1000XM4Coordinator.java index 0609ab44b..08f1ff618 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWH1000XM4Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWH1000XM4Coordinator.java @@ -20,23 +20,18 @@ import androidx.annotation.NonNull; import java.util.Arrays; import java.util.List; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCapabilities; import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCoordinator; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; -import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.SonyHeadphonesSupport; public class SonyWH1000XM4Coordinator extends SonyHeadphonesCoordinator { - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - if (candidate.getName().contains("WH-1000XM4")) { - return DeviceType.SONY_WH_1000XM4; - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(".*WH-1000XM4.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWH1000XM5Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWH1000XM5Coordinator.java index 92ed9170f..e77ecd604 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWH1000XM5Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWH1000XM5Coordinator.java @@ -20,6 +20,7 @@ import androidx.annotation.NonNull; import java.util.Arrays; import java.util.List; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCapabilities; @@ -28,14 +29,9 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; public class SonyWH1000XM5Coordinator extends SonyHeadphonesCoordinator { - @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - if (candidate.getName().contains("WH-1000XM5")) { - return DeviceType.SONY_WH_1000XM5; - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(".*WH-1000XM5.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/wena3/SonyWena3Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/wena3/SonyWena3Coordinator.java index 08af75e1b..5cd5bff7d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/wena3/SonyWena3Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/wena3/SonyWena3Coordinator.java @@ -27,6 +27,7 @@ import androidx.annotation.Nullable; import java.util.ArrayList; import java.util.Collection; +import java.util.regex.Pattern; import de.greenrobot.dao.query.QueryBuilder; import nodomain.freeyourgadget.gadgetbridge.R; @@ -126,15 +127,10 @@ public class SonyWena3Coordinator extends AbstractBLEDeviceCoordinator { qb.where(Wena3StressSampleDao.Properties.DeviceId.eq(deviceId)).buildDelete().executeDeleteWithoutDetachingEntities(); } - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - if(SonyWena3Constants.BT_DEVICE_NAME.equals(candidate.getName())) { - return DeviceType.SONY_WENA_3; - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(SonyWena3Constants.BT_DEVICE_NAME); } - @Override public int getBondingStyle() { return BONDING_STYLE_BOND; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sonyswr12/SonySWR12DeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sonyswr12/SonySWR12DeviceCoordinator.java index ec898f899..4e9de4bfc 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sonyswr12/SonySWR12DeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sonyswr12/SonySWR12DeviceCoordinator.java @@ -24,6 +24,8 @@ import android.net.Uri; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator; @@ -39,16 +41,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.sonyswr12.SonySWR12DeviceSupport; public class SonySWR12DeviceCoordinator extends AbstractBLEDeviceCoordinator { - - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - if (name != null && !name.isEmpty() && name.toLowerCase().contains("swr12")) - return DeviceType.SONY_SWR12; - } catch (Exception exc){} - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile(".*swr12.*", Pattern.CASE_INSENSITIVE); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/supercars/SuperCarsCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/supercars/SuperCarsCoordinator.java index f4c424f75..14fd2a456 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/supercars/SuperCarsCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/supercars/SuperCarsCoordinator.java @@ -10,6 +10,8 @@ import androidx.annotation.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator; @@ -32,21 +34,9 @@ public class SuperCarsCoordinator extends AbstractDeviceCoordinator { } - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - try { - String name = candidate.getName(); - - if (name != null && name.startsWith("QCAR-")) { - return DeviceType.SUPER_CARS; - } - - } catch (Exception ex) { - LOG.error("unable to check device support", ex); - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("QCAR-.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/test/TestDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/test/TestDeviceCoordinator.java index d0df667a9..fa2ea7cdf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/test/TestDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/test/TestDeviceCoordinator.java @@ -29,8 +29,8 @@ public class TestDeviceCoordinator extends AbstractDeviceCoordinator { @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - return DeviceType.UNKNOWN; + public boolean supports(GBDeviceCandidate candidate) { + return false; } @Nullable diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/tlw64/TLW64Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/tlw64/TLW64Coordinator.java index aea0fd5b2..5ba2e73f7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/tlw64/TLW64Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/tlw64/TLW64Coordinator.java @@ -25,6 +25,8 @@ import android.net.Uri; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator; @@ -45,15 +47,9 @@ public class TLW64Coordinator extends AbstractBLEDeviceCoordinator { protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException { } - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - if (name != null && name.startsWith("Smart Bee")) { - return DeviceType.TLW64; - } - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Smart Bee.*"); } @Nullable diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/um25/Coordinator/UM25Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/um25/Coordinator/UM25Coordinator.java index 2a6ec0e19..78a38e37e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/um25/Coordinator/UM25Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/um25/Coordinator/UM25Coordinator.java @@ -45,12 +45,12 @@ public class UM25Coordinator extends AbstractBLEDeviceCoordinator { @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - if(!"UM25C".equals(candidate.getName())) return DeviceType.UNKNOWN; + public boolean supports(GBDeviceCandidate candidate) { + if(!"UM25C".equals(candidate.getName())) return false; for(ParcelUuid service : candidate.getServiceUuids()){ - if(service.getUuid().toString().equals(UM25Support.UUID_SERVICE)) return DeviceType.UM25; + if(service.getUuid().toString().equals(UM25Support.UUID_SERVICE)) return true; } - return DeviceType.UNKNOWN; + return false; } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/vesc/VescCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/vesc/VescCoordinator.java index 45f15d75c..f5ccb0896 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/vesc/VescCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/vesc/VescCoordinator.java @@ -69,20 +69,16 @@ public class VescCoordinator extends AbstractBLEDeviceCoordinator { } @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { + public boolean supports(GBDeviceCandidate candidate) { ParcelUuid[] uuids = candidate.getServiceUuids(); - Logger logger = LoggerFactory.getLogger(getClass()); - for(ParcelUuid uuid: uuids){ - logger.debug("service: {}", uuid.toString()); - } for(ParcelUuid uuid : uuids){ if(uuid.getUuid().toString().equals(UUID_SERVICE_SERIAL_NRF)){ - return DeviceType.VESC_NRF; + return true; }else if(uuid.getUuid().toString().equals(UUID_SERVICE_SERIAL_HM10)){ - return DeviceType.VESC_HM10; + return true; } } - return DeviceType.UNKNOWN; + return false; } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/vibratissimo/VibratissimoCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/vibratissimo/VibratissimoCoordinator.java index d29b77d1e..8be69d1f6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/vibratissimo/VibratissimoCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/vibratissimo/VibratissimoCoordinator.java @@ -24,6 +24,7 @@ import android.net.Uri; import androidx.annotation.NonNull; import java.util.EnumSet; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator; @@ -40,14 +41,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.ServiceDeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.vibratissimo.VibratissimoSupport; public class VibratissimoCoordinator extends AbstractBLEDeviceCoordinator { - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - if (name != null && name.startsWith("Vibratissimo")) { - return DeviceType.VIBRATISSIMO; - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("Vibratissimo.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/vivomovehr/VivomoveHrCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/vivomovehr/VivomoveHrCoordinator.java index b4e1bd887..9e4eee176 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/vivomovehr/VivomoveHrCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/vivomovehr/VivomoveHrCoordinator.java @@ -26,7 +26,6 @@ import androidx.annotation.Nullable; import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator; -import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; @@ -44,11 +43,11 @@ import java.util.Collections; public class VivomoveHrCoordinator extends AbstractBLEDeviceCoordinator { @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - if ("vívomove HR".equals(candidate.getName())) return DeviceType.VIVOMOVE_HR; + public boolean supports(GBDeviceCandidate candidate) { + if ("vívomove HR".equals(candidate.getName())) return true; final boolean hasServiceUuids = candidate.getServiceUuids().length > 0; - return hasServiceUuids && candidate.supportsService(VivomoveConstants.UUID_SERVICE_GARMIN_GFDI) ? DeviceType.VIVOMOVE_HR : DeviceType.UNKNOWN; + return hasServiceUuids && candidate.supportsService(VivomoveConstants.UUID_SERVICE_GARMIN_GFDI); } @NonNull diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/waspos/WaspOSCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/waspos/WaspOSCoordinator.java index 68d66e9b1..3827f3e7b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/waspos/WaspOSCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/waspos/WaspOSCoordinator.java @@ -17,24 +17,22 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.waspos; -import android.annotation.TargetApi; import android.app.Activity; import android.bluetooth.le.ScanFilter; import android.content.Context; import android.net.Uri; -import android.os.Build; import android.os.ParcelUuid; import androidx.annotation.NonNull; import java.util.Collection; import java.util.Collections; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; -import nodomain.freeyourgadget.gadgetbridge.devices.waspos.WaspOSConstants; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.entities.Device; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; @@ -61,20 +59,9 @@ public class WaspOSCoordinator extends AbstractBLEDeviceCoordinator { return Collections.singletonList(filter); } - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - /* Filter by Espruino devices to avoid getting - the device chooser full of spam devices. */ - if (name != null && ( - name.startsWith("DS-D6") || - name.startsWith("K9") || - name.startsWith("PineTime") || - name.startsWith("P8"))) - return DeviceType.WASPOS; - - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("DS-D6.*|K9.*|PineTime.*|P8.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/watch9/Watch9DeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/watch9/Watch9DeviceCoordinator.java index eb01fd46c..061790ba1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/watch9/Watch9DeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/watch9/Watch9DeviceCoordinator.java @@ -17,12 +17,10 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.watch9; -import android.annotation.TargetApi; import android.app.Activity; import android.bluetooth.le.ScanFilter; import android.content.Context; import android.net.Uri; -import android.os.Build; import android.os.ParcelUuid; import java.util.Collection; @@ -62,19 +60,19 @@ public class Watch9DeviceCoordinator extends AbstractBLEDeviceCoordinator { @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { + public boolean supports(GBDeviceCandidate candidate) { String macAddress = candidate.getMacAddress().toUpperCase(); String deviceName = candidate.getName().toUpperCase(); if (candidate.supportsService(Watch9Constants.UUID_SERVICE_WATCH9)) { - return DeviceType.WATCH9; + return true; // add support for Watch X non-plus (same MAC address) // add support for Watch X Plus (same MAC address) } else if ((macAddress.startsWith("1C:87:79")) && ((!deviceName.equalsIgnoreCase("WATCH X")) && (!deviceName.equalsIgnoreCase("WATCH XPLUS")))) { - return DeviceType.WATCH9; + return true; } else if (deviceName.equals("WATCH 9")) { - return DeviceType.WATCH9; + return true; } - return DeviceType.UNKNOWN; + return false; } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/withingssteelhr/WithingsSteelHRDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/withingssteelhr/WithingsSteelHRDeviceCoordinator.java index d24327e08..6a42414db 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/withingssteelhr/WithingsSteelHRDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/withingssteelhr/WithingsSteelHRDeviceCoordinator.java @@ -52,13 +52,13 @@ public class WithingsSteelHRDeviceCoordinator extends AbstractDeviceCoordinator @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { + public boolean supports(GBDeviceCandidate candidate) { String name = candidate.getName(); if (name != null && (name.toLowerCase(Locale.ROOT).startsWith("steel") || name.toLowerCase(Locale.ROOT).startsWith("activite"))) { - return DeviceType.WITHINGS_STEEL_HR; + return true; } - return DeviceType.UNKNOWN; + return false; } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xwatch/XWatchCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xwatch/XWatchCoordinator.java index bb102ef0b..8cb4fb2c7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xwatch/XWatchCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xwatch/XWatchCoordinator.java @@ -23,6 +23,9 @@ import android.net.Uri; import androidx.annotation.NonNull; import androidx.annotation.Nullable; + +import java.util.regex.Pattern; + import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator; @@ -38,14 +41,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.xwatch.XWatchSupport; public class XWatchCoordinator extends AbstractBLEDeviceCoordinator { - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - if (name != null && name.startsWith("XWatch")) { - return DeviceType.XWATCH; - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("XWatch.*"); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/zetime/ZeTimeCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/zetime/ZeTimeCoordinator.java index ea7798819..771235bd2 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/zetime/ZeTimeCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/zetime/ZeTimeCoordinator.java @@ -26,6 +26,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import java.util.Collection; +import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator; @@ -48,16 +49,10 @@ public class ZeTimeCoordinator extends AbstractBLEDeviceCoordinator { return super.createBLEScanFilters(); } - @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - String name = candidate.getName(); - if (name != null && name.startsWith("ZeTime")) { - return DeviceType.ZETIME; - } - return DeviceType.UNKNOWN; + protected Pattern getSupportedDeviceName() { + return Pattern.compile("ZeTime.*"); } - @Nullable @Override public Class getPairingActivity() { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceType.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceType.java index a7651a9b8..5250555c6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceType.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceType.java @@ -257,8 +257,7 @@ public enum DeviceType { SONY_WH_1000XM5(437, SonyWH1000XM5Coordinator.class), SONY_WF_1000XM5(438, SonyWF1000XM5Coordinator.class), BOSE_QC35(440, QC35Coordinator.class), - VESC_NRF(500, VescCoordinator.class), - VESC_HM10(501, VescCoordinator.class), + VESC(500, VescCoordinator.class), BINARY_SENSOR(510, BinarySensorCoordinator.class), FLIPPER_ZERO(520, FlipperZeroCoordinator.class), SUPER_CARS(530, SuperCarsCoordinator.class), diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vesc/VescDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vesc/VescDeviceSupport.java index 2007b6f1d..f6ef830da 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vesc/VescDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vesc/VescDeviceSupport.java @@ -67,12 +67,8 @@ public class VescDeviceSupport extends VescBaseDeviceSupport { responseBuffer.order(ByteOrder.BIG_ENDIAN); deviceType = type; - - if (type == DeviceType.VESC_NRF) { - addSupportedService(UUID.fromString(VescCoordinator.UUID_SERVICE_SERIAL_NRF)); - } else if (type == DeviceType.VESC_HM10) { - addSupportedService(UUID.fromString(VescCoordinator.UUID_SERVICE_SERIAL_HM10)); - } + addSupportedService(UUID.fromString(VescCoordinator.UUID_SERVICE_SERIAL_NRF)); + addSupportedService(UUID.fromString(VescCoordinator.UUID_SERVICE_SERIAL_HM10)); } @Override @@ -89,10 +85,10 @@ public class VescDeviceSupport extends VescBaseDeviceSupport { initBroadcast(); - if (deviceType == DeviceType.VESC_NRF) { - this.serialWriteCharacteristic = getCharacteristic(UUID.fromString(VescCoordinator.UUID_CHARACTERISTIC_SERIAL_TX_NRF)); - this.serialReadCharacteristic = getCharacteristic(UUID.fromString(VescCoordinator.UUID_CHARACTERISTIC_SERIAL_RX_NRF)); - } else if (deviceType == DeviceType.VESC_HM10) { + + this.serialWriteCharacteristic = getCharacteristic(UUID.fromString(VescCoordinator.UUID_CHARACTERISTIC_SERIAL_TX_NRF)); + this.serialReadCharacteristic = getCharacteristic(UUID.fromString(VescCoordinator.UUID_CHARACTERISTIC_SERIAL_RX_NRF)); + if(this.serialWriteCharacteristic == null || this.serialReadCharacteristic == null){ this.serialWriteCharacteristic = getCharacteristic(UUID.fromString(VescCoordinator.UUID_CHARACTERISTIC_SERIAL_TX_HM10)); this.serialReadCharacteristic = getCharacteristic(UUID.fromString(VescCoordinator.UUID_CHARACTERISTIC_SERIAL_RX_HM10)); } diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/devices/sony/headphones/protocol/impl/MockSonyCoordinator.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/devices/sony/headphones/protocol/impl/MockSonyCoordinator.java index b2991e926..4ef079914 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/devices/sony/headphones/protocol/impl/MockSonyCoordinator.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/devices/sony/headphones/protocol/impl/MockSonyCoordinator.java @@ -34,8 +34,8 @@ public class MockSonyCoordinator extends SonyHeadphonesCoordinator { @NonNull @Override - public DeviceType getSupportedType(final GBDeviceCandidate candidate) { - return deviceType; + public boolean supports(final GBDeviceCandidate candidate) { + return true; } @Override