mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-28 19:45:50 +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:
parent
84c91021d1
commit
0f65e42be4
@ -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) {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user