1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-12 13:09:24 +01:00

huawei: Fix SendGpsData

Add Distance, startTime and endTime to GpsData.
Fixes non working GB assisted GPS on Huawei Band 8.

TEST: Confirmed that speed and distance is properly shown
      while using the cycling (outdoor) activity.
Fixes issue #3990.

Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
This commit is contained in:
Patrick Rudolph 2024-10-03 20:11:33 +02:00 committed by José Rebelo
parent 84c91021d1
commit 0f65e42be4
2 changed files with 22 additions and 2 deletions

View File

@ -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) {

View File

@ -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<GpsAndTime.GpsData.Request.GpsDataContainer> 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 {