1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 04:46:51 +01:00

Improve GPS support for Huawei gadgets

This commit is contained in:
Martin.JM 2024-05-30 23:02:41 +02:00 committed by José Rebelo
parent 0e9c709a59
commit 15ba9e6c85

View File

@ -22,7 +22,6 @@ import android.content.SharedPreferences;
import android.location.Location; import android.location.Location;
import android.net.Uri; import android.net.Uri;
import android.os.Handler; import android.os.Handler;
import android.os.SystemClock;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -184,6 +183,7 @@ public class HuaweiSupportProvider {
private MediaManager mediaManager = null; private MediaManager mediaManager = null;
private GpsAndTime.GpsParameters.Response gpsParametersResponse = null; private GpsAndTime.GpsParameters.Response gpsParametersResponse = null;
private boolean gpsEnabled = false;
private final HuaweiPacket.ParamsProvider paramsProvider = new HuaweiPacket.ParamsProvider(); private final HuaweiPacket.ParamsProvider paramsProvider = new HuaweiPacket.ParamsProvider();
@ -256,6 +256,12 @@ public class HuaweiSupportProvider {
gpsParameterRequest.setFinalizeReq(new RequestCallback() { gpsParameterRequest.setFinalizeReq(new RequestCallback() {
@Override @Override
public void call() { public void call() {
if (gpsEnabled) {
// Prevent adding multiple GPS providers
LOG.info("GPS is already enabled.");
return;
}
gpsEnabled = true;
GBLocationService.start(getContext(), getDevice(), GBLocationProviderType.GPS, 1000); GBLocationService.start(getContext(), getDevice(), GBLocationProviderType.GPS, 1000);
} }
}); });
@ -265,10 +271,19 @@ public class HuaweiSupportProvider {
GB.toast(context, "Failed to get GPS parameters", Toast.LENGTH_SHORT, GB.ERROR, e); GB.toast(context, "Failed to get GPS parameters", Toast.LENGTH_SHORT, GB.ERROR, e);
LOG.error("Failed to get GPS parameters", e); LOG.error("Failed to get GPS parameters", e);
} }
} else } else {
if (gpsEnabled) {
// Prevent adding multiple GPS providers
LOG.info("GPS is already enabled.");
return;
}
gpsEnabled = true;
GBLocationService.start(getContext(), getDevice(), GBLocationProviderType.GPS, 1000); GBLocationService.start(getContext(), getDevice(), GBLocationProviderType.GPS, 1000);
} else }
} else {
gpsEnabled = false;
GBLocationService.stop(getContext(), getDevice()); GBLocationService.stop(getContext(), getDevice());
}
} }
public void setGpsParametersResponse(GpsAndTime.GpsParameters.Response response) { public void setGpsParametersResponse(GpsAndTime.GpsParameters.Response response) {
@ -1879,6 +1894,12 @@ public class HuaweiSupportProvider {
return; return;
} }
if (!gpsEnabled) {
LOG.warn("Received GPS data without GPS being enabled! Attempting to stop again.");
GBLocationService.stop(getContext(), getDevice());
return;
}
SendGpsDataRequest sendGpsDataRequest = new SendGpsDataRequest(this, location, gpsParametersResponse); SendGpsDataRequest sendGpsDataRequest = new SendGpsDataRequest(this, location, gpsParametersResponse);
try { try {
sendGpsDataRequest.doPerform(); sendGpsDataRequest.doPerform();