Improve Location object.
Add getElapsedRealtimeNano(): Currently Location just has getTime() and setTime() based on UTC time. This is entirely unreliable since it is not guaranteed monotonic. There is a lot of code that compares fix age based on deltas - and it is all broken in the case of a system clock change. System clock can change when switching cellular networks (and in some cases when switching towers). Document the meaning of getAccuracy(): It is the horizontal, 95% confidence radius. Make some fields mandatory if they are reported by a LocationProvider: All Locations returned by a LocationProvider must include at the minimum a lat, long, timestamps, and accuracy. This is necessary to perform fused location. There are no public API's for applications to feed locations into a location provider so this should not cause any breakage. If a LocationProvider does not fill in enough fields on a Location object then it is dropped, and logged. Bug: 4305998 Change-Id: I7df77125d8a64e174d7bc8c2708661b4f33461ea
This commit is contained in:
@@ -1532,6 +1532,11 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
|
||||
throw new SecurityException("Requires INSTALL_LOCATION_PROVIDER permission");
|
||||
}
|
||||
|
||||
if (!location.isComplete()) {
|
||||
Log.w(TAG, "Dropping incomplete location: " + location);
|
||||
return;
|
||||
}
|
||||
|
||||
mLocationHandler.removeMessages(MESSAGE_LOCATION_CHANGED, location);
|
||||
Message m = Message.obtain(mLocationHandler, MESSAGE_LOCATION_CHANGED, location);
|
||||
m.arg1 = (passive ? 1 : 0);
|
||||
@@ -1588,7 +1593,8 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
|
||||
|
||||
// Check whether sufficient time has passed
|
||||
long minTime = record.mMinTime;
|
||||
if (loc.getTime() - lastLoc.getTime() < minTime - MAX_PROVIDER_SCHEDULING_JITTER) {
|
||||
long delta = (loc.getElapsedRealtimeNano() - lastLoc.getElapsedRealtimeNano()) / 1000000L;
|
||||
if (delta < minTime - MAX_PROVIDER_SCHEDULING_JITTER) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user