diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java index 4dfc85649..188a0d981 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java @@ -250,6 +250,7 @@ public class HuaweiSupportProvider { private GpsAndTime.GpsParameters.Response gpsParametersResponse = null; private boolean gpsEnabled = false; + private Location gpsLastLocation; private final HuaweiPacket.ParamsProvider paramsProvider = new HuaweiPacket.ParamsProvider(); @@ -379,6 +380,7 @@ public class HuaweiSupportProvider { } else { gpsEnabled = false; GBLocationService.stop(getContext(), getDevice()); + gpsLastLocation = null; } } @@ -1900,7 +1902,7 @@ public class HuaweiSupportProvider { return; } - SendGpsDataRequest sendGpsDataRequest = new SendGpsDataRequest(this, location, gpsParametersResponse); + SendGpsDataRequest sendGpsDataRequest = new SendGpsDataRequest(this, location, gpsLastLocation, gpsParametersResponse); try { sendGpsDataRequest.doPerform(); } catch (IOException e) { @@ -1908,6 +1910,7 @@ public class HuaweiSupportProvider { GB.toast(context, "Failed to send GPS data", Toast.LENGTH_SHORT, GB.ERROR, e); LOG.error("Failed to send GPS data", e); } + gpsLastLocation = location; } public void onInstallApp(Uri uri) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/SendGpsDataRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/SendGpsDataRequest.java index fadf5715b..fc8ff601a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/SendGpsDataRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/SendGpsDataRequest.java @@ -27,13 +27,15 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupport public class SendGpsDataRequest extends Request { Location location; + Location lastLocation; GpsAndTime.GpsParameters.Response gpsParametersResponse; - public SendGpsDataRequest(HuaweiSupportProvider support, Location location, GpsAndTime.GpsParameters.Response gpsParametersResponse) { + public SendGpsDataRequest(HuaweiSupportProvider support, Location location, Location lastLocation, GpsAndTime.GpsParameters.Response gpsParametersResponse) { super(support); this.serviceId = GpsAndTime.id; this.commandId = GpsAndTime.GpsData.id; this.location = location; + this.lastLocation = lastLocation; this.gpsParametersResponse = gpsParametersResponse; } @@ -42,6 +44,12 @@ public class SendGpsDataRequest extends Request { ArrayList gpsList = new ArrayList<>(); GpsAndTime.GpsData.Request.GpsDataContainer gpsData = new GpsAndTime.GpsData.Request.GpsDataContainer(); + long timeOffset = 1000; // Default 1 second sample time + float distance = 0.0f; + if (lastLocation != null) { + timeOffset = location.getTime() - lastLocation.getTime(); + distance = location.distanceTo(lastLocation); + } if (this.gpsParametersResponse.supportsSpeed && location.hasSpeed()) { gpsData.hasSpeed = true; gpsData.speed = (short) location.getSpeed(); @@ -63,6 +71,15 @@ public class SendGpsDataRequest extends Request { gpsData.hasAccuracy = true; gpsData.accuracy = location.getAccuracy(); } + if (this.gpsParametersResponse.supportsDistance) { + gpsData.hasDistance = true; + gpsData.distance = (int)distance; + } + long currentTime = System.currentTimeMillis(); + gpsData.hasStartTime = true; + gpsData.startTime = (int)((currentTime - timeOffset) / 1000); + gpsData.hasEndTime = true; + gpsData.endTime = (int)(currentTime / 1000); gpsList.add(gpsData); try {