mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-27 12:26:48 +01:00
Garmin: Fix rxnetworks AGPS header recognition
This commit is contained in:
parent
94572805e9
commit
d782169a64
@ -5,6 +5,8 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Arrays;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
@ -18,7 +20,7 @@ public class GarminAgpsFile {
|
||||
private final byte[] bytes;
|
||||
|
||||
public static final byte[] GZ_HEADER = new byte[]{(byte) 0x1f, (byte) 0x8b};
|
||||
public static final byte[] CPE_RXNETWORKS_HEADER = new byte[]{(byte) 0x01, (byte) 0x00, (byte) 0x66};
|
||||
public static final byte[] CPE_RXNETWORKS_HEADER = new byte[]{(byte) 0x01, (byte) 0x00};
|
||||
public static final byte[] CPE_SONY_HEADER = new byte[]{(byte) 0x2a, (byte) 0x12, (byte) 0xa0, (byte) 0x02};
|
||||
|
||||
public GarminAgpsFile(final byte[] bytes) {
|
||||
@ -59,6 +61,24 @@ public class GarminAgpsFile {
|
||||
LOG.error("Header in gz file is not agps rxnetworks: {}", GB.hexdump(header));
|
||||
return false;
|
||||
}
|
||||
final byte[] timestampBytes = new byte[4];
|
||||
read = gzis.read(timestampBytes);
|
||||
if (read != timestampBytes.length) {
|
||||
LOG.error("Failed to read rxnetworks timestamp");
|
||||
return false;
|
||||
}
|
||||
final int agpsTimestamp = ByteBuffer.wrap(timestampBytes).order(ByteOrder.BIG_ENDIAN).getInt();
|
||||
final int currentTimestamp = (int) (System.currentTimeMillis() / 1000L);
|
||||
final int agpsAge = currentTimestamp - agpsTimestamp;
|
||||
if (agpsAge < 0) {
|
||||
LOG.error("rxnetworks AGPS timestamp {} is in the future", agpsTimestamp);
|
||||
return false;
|
||||
}
|
||||
if (agpsAge > 604800) {
|
||||
LOG.error("rxnetworks AGPS timestamp {} is older than 7 days", agpsTimestamp);
|
||||
return false;
|
||||
}
|
||||
LOG.debug("rx networks AGPS age: {}", agpsAge);
|
||||
return true;
|
||||
} catch (final IOException e) {
|
||||
LOG.error("Failed to decompress file as gzip", e);
|
||||
|
Loading…
Reference in New Issue
Block a user