summaryrefslogtreecommitdiffstats
path: root/location/java
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@google.com>2010-01-29 20:12:21 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2010-01-29 20:12:21 -0800
commit21875ab33291d4c25bd9701e7ac51c589e665177 (patch)
treefb7cacaeeb629d9b81853b3af04b80d10bc3225b /location/java
parent1ef6fb3bbe17870673195f28eec9d1e4e43b4785 (diff)
parenta0460004aae7576114639393a230f18608d213e6 (diff)
downloadframeworks_base-21875ab33291d4c25bd9701e7ac51c589e665177.zip
frameworks_base-21875ab33291d4c25bd9701e7ac51c589e665177.tar.gz
frameworks_base-21875ab33291d4c25bd9701e7ac51c589e665177.tar.bz2
am a0460004: Merge "Ignore NTP time fixes that differ from system time by more than 5 minutes." into eclair
Merge commit 'a0460004aae7576114639393a230f18608d213e6' into eclair-plus-aosp * commit 'a0460004aae7576114639393a230f18608d213e6': Ignore NTP time fixes that differ from system time by more than 5 minutes.
Diffstat (limited to 'location/java')
-rwxr-xr-xlocation/java/com/android/internal/location/GpsLocationProvider.java34
1 files changed, 26 insertions, 8 deletions
diff --git a/location/java/com/android/internal/location/GpsLocationProvider.java b/location/java/com/android/internal/location/GpsLocationProvider.java
index 134756e..add2404 100755
--- a/location/java/com/android/internal/location/GpsLocationProvider.java
+++ b/location/java/com/android/internal/location/GpsLocationProvider.java
@@ -57,6 +57,7 @@ import java.io.StringBufferInputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
+import java.util.Date;
import java.util.Properties;
import java.util.Map.Entry;
@@ -240,10 +241,14 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
// how often to request NTP time, in milliseconds
// current setting 4 hours
- private static final long NTP_INTERVAL = 4*60*60*1000;
+ private static final long NTP_INTERVAL = 4*60*60*1000;
// how long to wait if we have a network error in NTP or XTRA downloading
// current setting - 5 minutes
- private static final long RETRY_INTERVAL = 5*60*1000;
+ private static final long RETRY_INTERVAL = 5*60*1000;
+
+ // to avoid injecting bad NTP time, we reject any time fixes that differ from system time
+ // by more than 5 minutes.
+ private static final long MAX_NTP_SYSTEM_TIME_OFFSET = 5*60*1000;
private final IGpsStatusProvider mGpsStatusProvider = new IGpsStatusProvider.Stub() {
public void addGpsStatusListener(IGpsStatusListener listener) throws RemoteException {
@@ -1253,13 +1258,26 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
long time = client.getNtpTime();
long timeReference = client.getNtpTimeReference();
int certainty = (int)(client.getRoundTripTime()/2);
+ long now = System.currentTimeMillis();
+ long systemTimeOffset = time - now;
- if (Config.LOGD) Log.d(TAG, "calling native_inject_time: " +
- time + " reference: " + timeReference
- + " certainty: " + certainty);
-
- native_inject_time(time, timeReference, certainty);
- mNextNtpTime = System.currentTimeMillis() + NTP_INTERVAL;
+ Log.d(TAG, "NTP server returned: "
+ + time + " (" + new Date(time)
+ + ") reference: " + timeReference
+ + " certainty: " + certainty
+ + " system time offset: " + systemTimeOffset);
+
+ // sanity check NTP time and do not use if it is too far from system time
+ if (systemTimeOffset < 0) {
+ systemTimeOffset = -systemTimeOffset;
+ }
+ if (systemTimeOffset < MAX_NTP_SYSTEM_TIME_OFFSET) {
+ native_inject_time(time, timeReference, certainty);
+ } else {
+ Log.e(TAG, "NTP time differs from system time by " + systemTimeOffset
+ + "ms. Ignoring.");
+ }
+ mNextNtpTime = now + NTP_INTERVAL;
} else {
if (Config.LOGD) Log.d(TAG, "requestTime failed");
mNextNtpTime = System.currentTimeMillis() + RETRY_INTERVAL;