1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-27 12:26:48 +01:00

PR-related improvements

- rename service identifiers for clarity
- define BLE scan filter in the coordinator (even though GB does not use those currently)
- rename `DownloadedFitFile` to `GarminFitFile`
- bump DB schema version to 49
This commit is contained in:
mormegil 2023-06-18 16:40:34 +02:00 committed by José Rebelo
parent dccb8ed1c4
commit a4ec3a62aa
4 changed files with 39 additions and 25 deletions

View File

@ -43,7 +43,7 @@ public class GBDaoGenerator {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
final Schema schema = new Schema(48, MAIN_PACKAGE + ".entities"); final Schema schema = new Schema(49, MAIN_PACKAGE + ".entities");
Entity userAttributes = addUserAttributes(schema); Entity userAttributes = addUserAttributes(schema);
Entity user = addUserInfo(schema, userAttributes); Entity user = addUserInfo(schema, userAttributes);
@ -92,7 +92,7 @@ public class GBDaoGenerator {
addPineTimeActivitySample(schema, user, device); addPineTimeActivitySample(schema, user, device);
addHybridHRActivitySample(schema, user, device); addHybridHRActivitySample(schema, user, device);
addVivomoveHrActivitySample(schema, user, device); addVivomoveHrActivitySample(schema, user, device);
addDownloadedFitFile(schema, user, device); addGarminFitFile(schema, user, device);
addCalendarSyncState(schema, device); addCalendarSyncState(schema, device);
addAlarms(schema, user, device); addAlarms(schema, user, device);
@ -476,10 +476,10 @@ public class GBDaoGenerator {
return activitySample; return activitySample;
} }
private static Entity addDownloadedFitFile(Schema schema, Entity user, Entity device) { private static Entity addGarminFitFile(Schema schema, Entity user, Entity device) {
final Entity downloadedFitFile = addEntity(schema, "DownloadedFitFile"); final Entity downloadedFitFile = addEntity(schema, "GarminFitFile");
downloadedFitFile.implementsSerializable(); downloadedFitFile.implementsSerializable();
downloadedFitFile.setJavaDoc("This class represents a single FIT file downloaded from a FIT-compatible device."); downloadedFitFile.setJavaDoc("This class represents a single FIT file downloaded from a FIT-compatible Garmin device.");
downloadedFitFile.addIdProperty().autoincrement(); downloadedFitFile.addIdProperty().autoincrement();
downloadedFitFile.addLongProperty("downloadTimestamp").notNull(); downloadedFitFile.addLongProperty("downloadTimestamp").notNull();
final Property deviceId = downloadedFitFile.addLongProperty("deviceId").notNull().getProperty(); final Property deviceId = downloadedFitFile.addLongProperty("deviceId").notNull().getProperty();

View File

@ -6,8 +6,8 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
public class VivomoveConstants { public class VivomoveConstants {
public static final UUID UUID_SERVICE_GARMIN_1 = UUID.fromString("6A4E2401-667B-11E3-949A-0800200C9A66"); public static final UUID UUID_SERVICE_GARMIN_GFDI = UUID.fromString("6A4E2401-667B-11E3-949A-0800200C9A66");
public static final UUID UUID_SERVICE_GARMIN_2 = UUID.fromString("6A4E2500-667B-11E3-949A-0800200C9A66"); public static final UUID UUID_SERVICE_GARMIN_REALTIME = UUID.fromString("6A4E2500-667B-11E3-949A-0800200C9A66");
public static final UUID UUID_CHARACTERISTIC_GARMIN_GFDI_SEND = UUID.fromString("6a4e4c80-667b-11e3-949a-0800200c9a66"); public static final UUID UUID_CHARACTERISTIC_GARMIN_GFDI_SEND = UUID.fromString("6a4e4c80-667b-11e3-949a-0800200c9a66");
public static final UUID UUID_CHARACTERISTIC_GARMIN_GFDI_RECEIVE = UUID.fromString("6a4ecd28-667b-11e3-949a-0800200c9a66"); public static final UUID UUID_CHARACTERISTIC_GARMIN_GFDI_RECEIVE = UUID.fromString("6a4ecd28-667b-11e3-949a-0800200c9a66");

View File

@ -1,11 +1,14 @@
package nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr; package nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr;
import android.app.Activity; import android.app.Activity;
import android.bluetooth.le.ScanFilter;
import android.content.Context; import android.content.Context;
import android.net.Uri; import android.net.Uri;
import android.os.ParcelUuid;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
@ -16,14 +19,25 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample; import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
public class VivomoveHrCoordinator extends AbstractDeviceCoordinator { import java.util.Collection;
import java.util.Collections;
public class VivomoveHrCoordinator extends AbstractBLEDeviceCoordinator {
@NonNull @NonNull
@Override @Override
public DeviceType getSupportedType(GBDeviceCandidate candidate) { public DeviceType getSupportedType(GBDeviceCandidate candidate) {
if ("vívomove HR".equals(candidate.getName())) return DeviceType.VIVOMOVE_HR; if ("vívomove HR".equals(candidate.getName())) return DeviceType.VIVOMOVE_HR;
final boolean hasServiceUuids = candidate.getServiceUuids().length > 0; final boolean hasServiceUuids = candidate.getServiceUuids().length > 0;
return hasServiceUuids && candidate.supportsService(VivomoveConstants.UUID_SERVICE_GARMIN_2) ? DeviceType.VIVOMOVE_HR : DeviceType.UNKNOWN; return hasServiceUuids && candidate.supportsService(VivomoveConstants.UUID_SERVICE_GARMIN_GFDI) ? DeviceType.VIVOMOVE_HR : DeviceType.UNKNOWN;
}
@NonNull
@Override
public Collection<? extends ScanFilter> createBLEScanFilters() {
final ParcelUuid garminService = new ParcelUuid(VivomoveConstants.UUID_SERVICE_GARMIN_GFDI);
final ScanFilter filter = new ScanFilter.Builder().setServiceUuid(garminService).build();
return Collections.singletonList(filter);
} }
@Override @Override

View File

@ -17,8 +17,8 @@ import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.GarminCapability;
import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.Device; import nodomain.freeyourgadget.gadgetbridge.entities.Device;
import nodomain.freeyourgadget.gadgetbridge.entities.DownloadedFitFile; import nodomain.freeyourgadget.gadgetbridge.entities.GarminFitFile;
import nodomain.freeyourgadget.gadgetbridge.entities.DownloadedFitFileDao; import nodomain.freeyourgadget.gadgetbridge.entities.GarminFitFileDao;
import nodomain.freeyourgadget.gadgetbridge.entities.User; import nodomain.freeyourgadget.gadgetbridge.entities.User;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec; import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
@ -137,8 +137,8 @@ public class VivomoveHrSupport extends AbstractBTLEDeviceSupport implements File
public VivomoveHrSupport() { public VivomoveHrSupport() {
super(LOG); super(LOG);
addSupportedService(VivomoveConstants.UUID_SERVICE_GARMIN_1); addSupportedService(VivomoveConstants.UUID_SERVICE_GARMIN_GFDI);
addSupportedService(VivomoveConstants.UUID_SERVICE_GARMIN_2); addSupportedService(VivomoveConstants.UUID_SERVICE_GARMIN_REALTIME);
} }
private int getNextProtobufRequestId() { private int getNextProtobufRequestId() {
@ -928,19 +928,19 @@ public class VivomoveHrSupport extends AbstractBTLEDeviceSupport implements File
private long totalDownloadSize; private long totalDownloadSize;
private long lastTransferNotificationTimestamp; private long lastTransferNotificationTimestamp;
private DownloadedFitFile findDownloadedFitFile(DaoSession session, Device device, User user, int fileNumber, int fileDataType, int fileSubType) { private GarminFitFile findDownloadedFitFile(DaoSession session, Device device, User user, int fileNumber, int fileDataType, int fileSubType) {
final DownloadedFitFileDao fileDao = session.getDownloadedFitFileDao(); final GarminFitFileDao fileDao = session.getGarminFitFileDao();
final Query<DownloadedFitFile> query = fileDao.queryBuilder() final Query<GarminFitFile> query = fileDao.queryBuilder()
.where( .where(
DownloadedFitFileDao.Properties.DeviceId.eq(device.getId()), GarminFitFileDao.Properties.DeviceId.eq(device.getId()),
DownloadedFitFileDao.Properties.UserId.eq(user.getId()), GarminFitFileDao.Properties.UserId.eq(user.getId()),
DownloadedFitFileDao.Properties.FileNumber.eq(fileNumber), GarminFitFileDao.Properties.FileNumber.eq(fileNumber),
DownloadedFitFileDao.Properties.FileDataType.eq(fileDataType), GarminFitFileDao.Properties.FileDataType.eq(fileDataType),
DownloadedFitFileDao.Properties.FileSubType.eq(fileSubType) GarminFitFileDao.Properties.FileSubType.eq(fileSubType)
) )
.build(); .build();
final List<DownloadedFitFile> files = query.list(); final List<GarminFitFile> files = query.list();
return files.size() > 0 ? files.get(0) : null; return files.size() > 0 ? files.get(0) : null;
} }
@ -967,7 +967,7 @@ public class VivomoveHrSupport extends AbstractBTLEDeviceSupport implements File
} }
final long timestamp = entry.fileDate.getTime(); final long timestamp = entry.fileDate.getTime();
final DownloadedFitFile alreadyDownloadedFile = findDownloadedFitFile(session, device, user, entry.fileNumber, entry.fileDataType, entry.fileSubType); final GarminFitFile alreadyDownloadedFile = findDownloadedFitFile(session, device, user, entry.fileNumber, entry.fileDataType, entry.fileSubType);
if (alreadyDownloadedFile == null) { if (alreadyDownloadedFile == null) {
LOG.debug("File not yet downloaded"); LOG.debug("File not yet downloaded");
} else { } else {
@ -1007,8 +1007,8 @@ public class VivomoveHrSupport extends AbstractBTLEDeviceSupport implements File
final User user = DBHelper.getUser(session); final User user = DBHelper.getUser(session);
final int ts = (int) (System.currentTimeMillis() / 1000); final int ts = (int) (System.currentTimeMillis() / 1000);
final DownloadedFitFile downloadedFitFile = new DownloadedFitFile(null, ts, device.getId(), user.getId(), downloadedDirectoryEntry.fileNumber, downloadedDirectoryEntry.fileDataType, downloadedDirectoryEntry.fileSubType, downloadedDirectoryEntry.fileDate.getTime(), downloadedDirectoryEntry.specificFlags, downloadedDirectoryEntry.fileSize, STORE_FIT_FILES ? data : null); final GarminFitFile garminFitFile = new GarminFitFile(null, ts, device.getId(), user.getId(), downloadedDirectoryEntry.fileNumber, downloadedDirectoryEntry.fileDataType, downloadedDirectoryEntry.fileSubType, downloadedDirectoryEntry.fileDate.getTime(), downloadedDirectoryEntry.specificFlags, downloadedDirectoryEntry.fileSize, STORE_FIT_FILES ? data : null);
session.getDownloadedFitFileDao().insert(downloadedFitFile); session.getGarminFitFileDao().insert(garminFitFile);
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error saving downloaded file to database", e); LOG.error("Error saving downloaded file to database", e);
} }