2024-01-30 16:17:59 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests;
|
|
|
|
|
2024-02-04 18:10:14 +01:00
|
|
|
import java.util.Calendar;
|
2024-01-30 16:17:59 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2024-02-04 18:10:14 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2024-01-30 16:17:59 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.GpsAndTime;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
|
2024-02-04 18:10:14 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
2024-01-30 16:17:59 +01:00
|
|
|
|
|
|
|
public class SendGpsAndTimeToDeviceRequest extends Request {
|
|
|
|
|
|
|
|
public SendGpsAndTimeToDeviceRequest(HuaweiSupportProvider support) {
|
|
|
|
super(support);
|
|
|
|
this.serviceId = GpsAndTime.id;
|
|
|
|
this.commandId = GpsAndTime.CurrentGPSRequest.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
|
|
|
try {
|
|
|
|
// TODO: support multiple units
|
|
|
|
|
2024-02-04 18:10:14 +01:00
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
|
|
|
// Backdating a bit seems to work better
|
2024-01-30 16:17:59 +01:00
|
|
|
return new GpsAndTime.CurrentGPSRequest(
|
2024-02-04 18:10:14 +01:00
|
|
|
this.paramsProvider,
|
|
|
|
(int) (Calendar.getInstance().getTime().getTime() / 1000L) - 60,
|
|
|
|
prefs.getFloat("location_latitude", 0),
|
|
|
|
prefs.getFloat("location_longitude", 0)
|
2024-01-30 16:17:59 +01:00
|
|
|
).serialize();
|
|
|
|
} catch (HuaweiPacket.CryptoException e) {
|
|
|
|
throw new RequestCreationException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|