2021-01-10 23:37:09 +01:00
|
|
|
/* Copyright (C) 2015-2021 0nse, 115ek, Andreas Böhler, Andreas Shimokawa,
|
|
|
|
angelpup, Carsten Pfeiffer, Cre3per, DanialHanif, Daniel Dakhno, Daniele
|
|
|
|
Gobbetti, Dmytro Bielik, Gordon Williams, Jean-François Greffier, João Paulo
|
|
|
|
Barraca, José Rebelo, ksiwczynski, ladbsoft, Lesur Frederic, Manuel Ruß,
|
|
|
|
maxirnilian, mkusnierz, odavo32nof, opavlov, pangwalla, Pavel Elagin,
|
|
|
|
protomors, Quallenauge, Sami Alaoui, Sebastian Kranz, Sophanimus, Taavi
|
|
|
|
Eomäe, tiparega, Vadim Kaushan, Yukai Li
|
2017-03-10 14:53:19 +01:00
|
|
|
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.util;
|
2015-05-05 00:48:02 +02:00
|
|
|
|
2015-12-13 00:43:07 +01:00
|
|
|
import android.bluetooth.BluetoothAdapter;
|
2015-10-18 01:01:13 +02:00
|
|
|
import android.bluetooth.BluetoothDevice;
|
2015-12-13 00:43:07 +01:00
|
|
|
import android.content.Context;
|
|
|
|
import android.widget.Toast;
|
2015-10-18 01:01:13 +02:00
|
|
|
|
2016-05-07 21:46:20 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2016-09-30 22:57:16 +02:00
|
|
|
import java.lang.reflect.Method;
|
2015-05-05 00:48:02 +02:00
|
|
|
import java.util.ArrayList;
|
2016-08-31 00:33:54 +02:00
|
|
|
import java.util.Collections;
|
2015-12-13 00:43:07 +01:00
|
|
|
import java.util.LinkedHashSet;
|
2015-05-05 00:48:02 +02:00
|
|
|
import java.util.List;
|
2015-12-13 00:43:07 +01:00
|
|
|
import java.util.Set;
|
2015-05-05 00:48:02 +02:00
|
|
|
|
2016-04-25 23:18:55 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2016-09-30 23:07:30 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
2015-12-13 00:43:07 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2016-08-31 00:33:54 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.UnknownDeviceCoordinator;
|
2019-11-28 19:02:47 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.banglejs.BangleJSCoordinator;
|
2020-11-14 20:43:19 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.casio.gb6900.CasioGB6900DeviceCoordinator;
|
2020-11-14 23:15:14 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.casio.gbx100.CasioGBX100DeviceCoordinator;
|
2017-09-10 20:40:10 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.EXRIZUK8Coordinator;
|
2016-12-21 13:51:25 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusCoordinator;
|
2017-01-23 01:08:36 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.MakibesF68Coordinator;
|
2020-08-02 10:55:06 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.Q8Coordinator;
|
2020-08-25 04:24:07 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.SG2Coordinator;
|
2020-10-17 11:58:22 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitband5.AmazfitBand5Coordinator;
|
2021-02-11 15:01:02 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbips.AmazfitBipSLiteCoordinator;
|
2021-01-26 23:30:43 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgts2.AmazfitGTS2MiniCoordinator;
|
2021-02-11 12:56:00 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgts2.AmazfitGTS2eCoordinator;
|
2021-01-20 16:03:58 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitneo.AmazfitNeoCoordinator;
|
2020-08-02 10:55:06 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipCoordinator;
|
2019-10-09 21:33:55 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipLiteCoordinator;
|
2020-03-23 11:58:14 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbips.AmazfitBipSCoordinator;
|
2020-11-30 23:38:37 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbipu.AmazfitBipUCoordinator;
|
2021-01-03 11:27:27 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbipupro.AmazfitBipUProCoordinator;
|
2020-08-02 10:55:06 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitcor.AmazfitCorCoordinator;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitcor2.AmazfitCor2Coordinator;
|
2019-10-22 21:53:38 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgtr.AmazfitGTRCoordinator;
|
2020-05-02 23:38:58 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgtr.AmazfitGTRLiteCoordinator;
|
2020-11-09 20:53:02 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgtr2.AmazfitGTR2Coordinator;
|
2021-02-07 12:07:02 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitx.AmazfitXCoordinator;
|
2021-01-31 22:41:01 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.zeppe.ZeppECoordinator;
|
2021-02-04 23:15:16 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgtr2.AmazfitGTR2eCoordinator;
|
2019-10-28 22:40:07 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgts.AmazfitGTSCoordinator;
|
2020-12-28 22:07:10 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgts2.AmazfitGTS2Coordinator;
|
2020-12-20 22:39:51 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitvergel.AmazfitVergeLCoordinator;
|
2020-08-02 10:55:06 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfittrex.AmazfitTRexCoordinator;
|
2017-10-23 14:46:08 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband2.MiBand2Coordinator;
|
2017-10-23 10:28:54 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband2.MiBand2HRXCoordinator;
|
2018-06-14 18:16:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband3.MiBand3Coordinator;
|
2019-06-12 23:44:01 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband4.MiBand4Coordinator;
|
2020-07-28 18:16:56 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband5.MiBand5Coordinator;
|
2018-07-12 14:47:08 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.id115.ID115Coordinator;
|
2020-08-02 10:55:06 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.itag.ITagCoordinator;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.jyou.BFH16DeviceCoordinator;
|
2018-09-27 00:05:40 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.jyou.TeclastH30.TeclastH30Coordinator;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.jyou.y5.Y5Coordinator;
|
2020-09-29 04:33:53 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.lefun.LefunDeviceCoordinator;
|
2020-08-02 10:55:06 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.lenovo.watchxplus.WatchXPlusDeviceCoordinator;
|
2016-11-20 21:23:47 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.liveview.LiveviewCoordinator;
|
2020-08-02 10:55:06 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.makibeshr3.MakibesHR3Coordinator;
|
2015-12-13 00:43:07 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandCoordinator;
|
2019-08-02 23:49:14 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.mijia_lywsd02.MijiaLywsd02Coordinator;
|
2019-05-09 12:42:59 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.miscale2.MiScale2DeviceCoordinator;
|
2017-08-29 17:28:30 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.no1f1.No1F1Coordinator;
|
2020-10-02 01:02:13 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.nut.NutCoordinator;
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleCoordinator;
|
2020-08-03 20:19:00 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.pinetime.PineTimeJFCoordinator;
|
2019-07-14 19:45:40 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.QHybridCoordinator;
|
2019-01-26 15:52:40 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.roidmi.Roidmi1Coordinator;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.roidmi.Roidmi3Coordinator;
|
2020-09-01 22:15:20 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.sonyswr12.SonySWR12DeviceCoordinator;
|
2020-06-29 23:02:38 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.tlw64.TLW64Coordinator;
|
2020-10-10 16:45:34 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.um25.Coordinator.UM25Coordinator;
|
2016-09-19 12:37:41 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.vibratissimo.VibratissimoCoordinator;
|
2020-12-23 21:55:23 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.waspos.WaspOSCoordinator;
|
2018-08-05 18:52:44 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.watch9.Watch9DeviceCoordinator;
|
2018-02-25 12:05:36 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.xwatch.XWatchCoordinator;
|
2018-02-08 07:21:12 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.zetime.ZeTimeCoordinator;
|
2016-08-31 00:33:54 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes;
|
2015-09-24 14:45:21 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
2015-12-13 00:43:07 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
2015-05-05 00:48:02 +02:00
|
|
|
|
|
|
|
public class DeviceHelper {
|
2016-05-07 21:46:20 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(DeviceHelper.class);
|
|
|
|
|
2015-11-23 23:04:46 +01:00
|
|
|
private static final DeviceHelper instance = new DeviceHelper();
|
2019-10-12 20:15:09 +02:00
|
|
|
// lazily created
|
|
|
|
private List<DeviceCoordinator> coordinators;
|
2015-05-05 00:48:02 +02:00
|
|
|
|
|
|
|
public static DeviceHelper getInstance() {
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2016-11-27 01:09:20 +01:00
|
|
|
public DeviceType getSupportedType(GBDeviceCandidate candidate) {
|
2015-05-05 00:48:02 +02:00
|
|
|
for (DeviceCoordinator coordinator : getAllCoordinators()) {
|
2016-11-27 01:09:20 +01:00
|
|
|
DeviceType deviceType = coordinator.getSupportedType(candidate);
|
|
|
|
if (deviceType.isSupported()) {
|
|
|
|
return deviceType;
|
2015-05-05 00:48:02 +02:00
|
|
|
}
|
|
|
|
}
|
2016-11-27 01:09:20 +01:00
|
|
|
return DeviceType.UNKNOWN;
|
2015-05-05 00:48:02 +02:00
|
|
|
}
|
|
|
|
|
2016-11-27 01:09:20 +01:00
|
|
|
public boolean getSupportedType(GBDevice device) {
|
2016-08-31 00:33:54 +02:00
|
|
|
for (DeviceCoordinator coordinator : getAllCoordinators()) {
|
|
|
|
if (coordinator.supports(device)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-13 00:43:07 +01:00
|
|
|
public GBDevice findAvailableDevice(String deviceAddress, Context context) {
|
|
|
|
Set<GBDevice> availableDevices = getAvailableDevices(context);
|
|
|
|
for (GBDevice availableDevice : availableDevices) {
|
|
|
|
if (deviceAddress.equals(availableDevice.getAddress())) {
|
|
|
|
return availableDevice;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-06-18 23:40:37 +02:00
|
|
|
/**
|
|
|
|
* Returns the list of all available devices that are supported by Gadgetbridge.
|
|
|
|
* Note that no state is known about the returned devices. Even if one of those
|
|
|
|
* devices is connected, it will report the default not-connected state.
|
|
|
|
*
|
|
|
|
* Clients interested in the "live" devices being managed should use the class
|
|
|
|
* DeviceManager.
|
|
|
|
* @param context
|
|
|
|
* @return
|
|
|
|
*/
|
2015-12-13 00:43:07 +01:00
|
|
|
public Set<GBDevice> getAvailableDevices(Context context) {
|
|
|
|
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
|
|
|
|
|
|
|
|
if (btAdapter == null) {
|
|
|
|
GB.toast(context, context.getString(R.string.bluetooth_is_not_supported_), Toast.LENGTH_SHORT, GB.WARN);
|
|
|
|
} else if (!btAdapter.isEnabled()) {
|
|
|
|
GB.toast(context, context.getString(R.string.bluetooth_is_disabled_), Toast.LENGTH_SHORT, GB.WARN);
|
2016-09-02 10:54:32 +02:00
|
|
|
}
|
|
|
|
|
2020-08-26 04:28:03 +02:00
|
|
|
Set<GBDevice> availableDevices = new LinkedHashSet<>(getDatabaseDevices());
|
2016-09-02 10:54:32 +02:00
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
2020-08-26 04:28:03 +02:00
|
|
|
String miAddress = prefs.getString(MiBandConst.PREF_MIBAND_ADDRESS, "");
|
|
|
|
if (miAddress.length() > 0) {
|
|
|
|
GBDevice miDevice = new GBDevice(miAddress, "MI", null, DeviceType.MIBAND);
|
2016-09-29 22:40:16 +02:00
|
|
|
availableDevices.add(miDevice);
|
2016-09-02 10:54:32 +02:00
|
|
|
}
|
2015-12-13 00:43:07 +01:00
|
|
|
|
2016-09-02 10:54:32 +02:00
|
|
|
String pebbleEmuAddr = prefs.getString("pebble_emu_addr", "");
|
|
|
|
String pebbleEmuPort = prefs.getString("pebble_emu_port", "");
|
|
|
|
if (pebbleEmuAddr.length() >= 7 && pebbleEmuPort.length() > 0) {
|
2020-06-12 18:04:53 +02:00
|
|
|
GBDevice pebbleEmuDevice = new GBDevice(pebbleEmuAddr + ":" + pebbleEmuPort, "Pebble qemu", "", DeviceType.PEBBLE);
|
2016-09-02 10:54:32 +02:00
|
|
|
availableDevices.add(pebbleEmuDevice);
|
2015-12-13 00:43:07 +01:00
|
|
|
}
|
|
|
|
return availableDevices;
|
|
|
|
}
|
|
|
|
|
2015-10-18 01:01:13 +02:00
|
|
|
public GBDevice toSupportedDevice(BluetoothDevice device) {
|
2016-11-27 02:41:52 +01:00
|
|
|
GBDeviceCandidate candidate = new GBDeviceCandidate(device, GBDevice.RSSI_UNKNOWN, device.getUuids());
|
2017-01-26 00:11:52 +01:00
|
|
|
return toSupportedDevice(candidate);
|
|
|
|
}
|
2016-05-07 21:46:20 +02:00
|
|
|
|
2017-01-26 00:11:52 +01:00
|
|
|
public GBDevice toSupportedDevice(GBDeviceCandidate candidate) {
|
2015-10-18 01:01:13 +02:00
|
|
|
for (DeviceCoordinator coordinator : getAllCoordinators()) {
|
|
|
|
if (coordinator.supports(candidate)) {
|
2016-08-18 21:29:26 +02:00
|
|
|
return coordinator.createDevice(candidate);
|
2015-10-18 01:01:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-08-03 23:09:49 +02:00
|
|
|
public DeviceCoordinator getCoordinator(GBDeviceCandidate device) {
|
2015-05-05 00:48:02 +02:00
|
|
|
synchronized (this) {
|
|
|
|
for (DeviceCoordinator coord : getAllCoordinators()) {
|
|
|
|
if (coord.supports(device)) {
|
2016-10-10 20:50:50 +02:00
|
|
|
return coord;
|
2015-05-05 00:48:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new UnknownDeviceCoordinator();
|
|
|
|
}
|
|
|
|
|
|
|
|
public DeviceCoordinator getCoordinator(GBDevice device) {
|
|
|
|
synchronized (this) {
|
|
|
|
for (DeviceCoordinator coord : getAllCoordinators()) {
|
|
|
|
if (coord.supports(device)) {
|
2016-10-10 20:50:50 +02:00
|
|
|
return coord;
|
2015-05-05 00:48:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new UnknownDeviceCoordinator();
|
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized List<DeviceCoordinator> getAllCoordinators() {
|
|
|
|
if (coordinators == null) {
|
|
|
|
coordinators = createCoordinators();
|
|
|
|
}
|
|
|
|
return coordinators;
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<DeviceCoordinator> createCoordinators() {
|
2017-01-28 22:43:48 +01:00
|
|
|
List<DeviceCoordinator> result = new ArrayList<>();
|
2019-10-12 20:15:09 +02:00
|
|
|
result.add(new MiScale2DeviceCoordinator());
|
2021-02-07 12:07:02 +01:00
|
|
|
result.add(new AmazfitXCoordinator());
|
2019-10-12 20:15:09 +02:00
|
|
|
result.add(new AmazfitBipCoordinator());
|
|
|
|
result.add(new AmazfitBipLiteCoordinator());
|
|
|
|
result.add(new AmazfitCorCoordinator());
|
|
|
|
result.add(new AmazfitCor2Coordinator());
|
2019-10-22 21:53:38 +02:00
|
|
|
result.add(new AmazfitGTRCoordinator());
|
2020-05-02 23:38:58 +02:00
|
|
|
result.add(new AmazfitGTRLiteCoordinator());
|
2020-11-09 20:53:02 +01:00
|
|
|
result.add(new AmazfitGTR2Coordinator());
|
2021-01-31 22:41:01 +01:00
|
|
|
result.add(new ZeppECoordinator());
|
2021-02-02 23:06:11 +01:00
|
|
|
result.add(new AmazfitGTR2eCoordinator());
|
2020-06-24 17:43:23 +02:00
|
|
|
result.add(new AmazfitTRexCoordinator());
|
2019-10-28 22:40:07 +01:00
|
|
|
result.add(new AmazfitGTSCoordinator());
|
2020-12-28 22:07:10 +01:00
|
|
|
result.add(new AmazfitGTS2Coordinator());
|
2021-02-11 12:56:00 +01:00
|
|
|
result.add(new AmazfitGTS2eCoordinator());
|
2021-01-26 23:30:43 +01:00
|
|
|
result.add(new AmazfitGTS2MiniCoordinator());
|
2020-12-20 22:39:51 +01:00
|
|
|
result.add(new AmazfitVergeLCoordinator());
|
2020-03-23 11:58:14 +01:00
|
|
|
result.add(new AmazfitBipSCoordinator());
|
2021-02-11 15:01:02 +01:00
|
|
|
result.add(new AmazfitBipSLiteCoordinator());
|
2020-11-30 23:38:37 +01:00
|
|
|
result.add(new AmazfitBipUCoordinator());
|
2021-01-03 11:27:27 +01:00
|
|
|
result.add(new AmazfitBipUProCoordinator());
|
2020-10-17 11:58:22 +02:00
|
|
|
result.add(new AmazfitBand5Coordinator());
|
2021-01-20 16:03:58 +01:00
|
|
|
result.add(new AmazfitNeoCoordinator());
|
2019-10-12 20:15:09 +02:00
|
|
|
result.add(new MiBand3Coordinator());
|
|
|
|
result.add(new MiBand4Coordinator());
|
2020-10-17 11:58:22 +02:00
|
|
|
result.add(new MiBand5Coordinator());
|
2019-10-12 20:15:09 +02:00
|
|
|
result.add(new MiBand2HRXCoordinator());
|
|
|
|
result.add(new MiBand2Coordinator()); // Note: MiBand2 and all of the above must come before MiBand because detection is hacky, atm
|
2015-05-05 00:48:02 +02:00
|
|
|
result.add(new MiBandCoordinator());
|
|
|
|
result.add(new PebbleCoordinator());
|
2016-09-19 12:37:41 +02:00
|
|
|
result.add(new VibratissimoCoordinator());
|
2016-11-20 21:23:47 +01:00
|
|
|
result.add(new LiveviewCoordinator());
|
2016-12-21 13:51:25 +01:00
|
|
|
result.add(new HPlusCoordinator());
|
2017-08-29 17:28:30 +02:00
|
|
|
result.add(new No1F1Coordinator());
|
2017-01-23 01:08:36 +01:00
|
|
|
result.add(new MakibesF68Coordinator());
|
2018-05-20 19:15:22 +02:00
|
|
|
result.add(new Q8Coordinator());
|
2017-09-10 20:40:10 +02:00
|
|
|
result.add(new EXRIZUK8Coordinator());
|
2017-09-04 08:43:34 +02:00
|
|
|
result.add(new TeclastH30Coordinator());
|
2018-02-25 12:05:36 +01:00
|
|
|
result.add(new XWatchCoordinator());
|
2019-07-14 19:45:40 +02:00
|
|
|
result.add(new QHybridCoordinator());
|
2018-02-08 07:21:12 +01:00
|
|
|
result.add(new ZeTimeCoordinator());
|
2018-07-12 14:47:08 +02:00
|
|
|
result.add(new ID115Coordinator());
|
2018-08-05 18:52:44 +02:00
|
|
|
result.add(new Watch9DeviceCoordinator());
|
2019-03-14 03:58:57 +01:00
|
|
|
result.add(new WatchXPlusDeviceCoordinator());
|
2018-08-31 13:39:51 +02:00
|
|
|
result.add(new Roidmi1Coordinator());
|
|
|
|
result.add(new Roidmi3Coordinator());
|
2018-09-27 00:05:40 +02:00
|
|
|
result.add(new Y5Coordinator());
|
2018-12-28 13:27:03 +01:00
|
|
|
result.add(new CasioGB6900DeviceCoordinator());
|
2020-11-14 23:15:14 +01:00
|
|
|
result.add(new CasioGBX100DeviceCoordinator());
|
2019-04-02 22:32:16 +02:00
|
|
|
result.add(new BFH16DeviceCoordinator());
|
2019-08-02 23:49:14 +02:00
|
|
|
result.add(new MijiaLywsd02Coordinator());
|
2020-01-31 22:18:17 +01:00
|
|
|
result.add(new ITagCoordinator());
|
2020-10-02 01:02:13 +02:00
|
|
|
result.add(new NutCoordinator());
|
2019-10-02 22:57:31 +02:00
|
|
|
result.add(new MakibesHR3Coordinator());
|
2019-11-28 19:02:47 +01:00
|
|
|
result.add(new BangleJSCoordinator());
|
2020-06-29 23:02:38 +02:00
|
|
|
result.add(new TLW64Coordinator());
|
2020-08-03 20:19:00 +02:00
|
|
|
result.add(new PineTimeJFCoordinator());
|
2020-08-25 04:24:07 +02:00
|
|
|
result.add(new SG2Coordinator());
|
2020-09-29 04:33:53 +02:00
|
|
|
result.add(new LefunDeviceCoordinator());
|
2020-09-01 22:15:20 +02:00
|
|
|
result.add(new SonySWR12DeviceCoordinator());
|
2020-12-23 21:55:23 +01:00
|
|
|
result.add(new WaspOSCoordinator());
|
2020-10-10 16:45:34 +02:00
|
|
|
result.add(new UM25Coordinator());
|
2017-01-23 01:08:36 +01:00
|
|
|
|
2015-05-05 00:48:02 +02:00
|
|
|
return result;
|
|
|
|
}
|
2016-08-31 00:33:54 +02:00
|
|
|
|
|
|
|
private List<GBDevice> getDatabaseDevices() {
|
|
|
|
List<GBDevice> result = new ArrayList<>();
|
|
|
|
try (DBHandler lockHandler = GBApplication.acquireDB()) {
|
|
|
|
List<Device> activeDevices = DBHelper.getActiveDevices(lockHandler.getDaoSession());
|
|
|
|
for (Device dbDevice : activeDevices) {
|
|
|
|
GBDevice gbDevice = toGBDevice(dbDevice);
|
2016-11-27 01:09:20 +01:00
|
|
|
if (gbDevice != null && DeviceHelper.getInstance().getSupportedType(gbDevice)) {
|
2016-08-31 00:33:54 +02:00
|
|
|
result.add(gbDevice);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
2020-08-02 10:55:06 +02:00
|
|
|
GB.toast(GBApplication.getContext().getString(R.string.error_retrieving_devices_database), Toast.LENGTH_SHORT, GB.ERROR, e);
|
2016-08-31 00:33:54 +02:00
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a known device from the database to a GBDevice.
|
|
|
|
* Note: The device might not be supported anymore, so callers should verify that.
|
|
|
|
* @param dbDevice
|
|
|
|
* @return
|
|
|
|
*/
|
2016-11-27 09:49:28 +01:00
|
|
|
public GBDevice toGBDevice(Device dbDevice) {
|
2016-08-31 00:33:54 +02:00
|
|
|
DeviceType deviceType = DeviceType.fromKey(dbDevice.getType());
|
2020-06-12 18:04:53 +02:00
|
|
|
GBDevice gbDevice = new GBDevice(dbDevice.getIdentifier(), dbDevice.getName(), dbDevice.getAlias(), deviceType);
|
2016-08-31 00:33:54 +02:00
|
|
|
List<DeviceAttributes> deviceAttributesList = dbDevice.getDeviceAttributesList();
|
|
|
|
if (deviceAttributesList.size() > 0) {
|
|
|
|
gbDevice.setModel(dbDevice.getModel());
|
|
|
|
DeviceAttributes attrs = deviceAttributesList.get(0);
|
|
|
|
gbDevice.setFirmwareVersion(attrs.getFirmwareVersion1());
|
|
|
|
gbDevice.setFirmwareVersion2(attrs.getFirmwareVersion2());
|
2016-11-27 09:49:28 +01:00
|
|
|
gbDevice.setVolatileAddress(attrs.getVolatileIdentifier());
|
2016-08-31 00:33:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return gbDevice;
|
|
|
|
}
|
|
|
|
|
2016-09-30 22:57:16 +02:00
|
|
|
/**
|
|
|
|
* Attempts to removing the bonding with the given device. Returns true
|
|
|
|
* if bonding was supposedly successful and false if anything went wrong
|
|
|
|
* @param device
|
|
|
|
* @return
|
|
|
|
*/
|
2016-09-30 23:07:30 +02:00
|
|
|
public boolean removeBond(GBDevice device) throws GBException {
|
2016-09-30 22:57:16 +02:00
|
|
|
BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
|
|
|
|
if (defaultAdapter != null) {
|
|
|
|
BluetoothDevice remoteDevice = defaultAdapter.getRemoteDevice(device.getAddress());
|
|
|
|
if (remoteDevice != null) {
|
|
|
|
try {
|
|
|
|
Method method = BluetoothDevice.class.getMethod("removeBond", (Class[]) null);
|
|
|
|
Object result = method.invoke(remoteDevice, (Object[]) null);
|
|
|
|
return Boolean.TRUE.equals(result);
|
|
|
|
} catch (Exception e) {
|
2016-09-30 23:07:30 +02:00
|
|
|
throw new GBException("Error removing bond to device: " + device, e);
|
2016-09-30 22:57:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2017-02-25 22:02:40 +01:00
|
|
|
|
2015-05-05 00:48:02 +02:00
|
|
|
}
|