diff options
| author | 2012-10-04 17:00:10 -0700 | |
|---|---|---|
| committer | 2012-10-04 17:23:12 -0700 | |
| commit | 60ec50a850ac7265b662df3c872583b6ef581ef8 (patch) | |
| tree | 4087f394f53373bfec6878041de9b3b3f30f481f | |
| parent | dfc8e799ed7500c1a07d4ba1f72e77d3de0f803a (diff) | |
Last position improvements for GeofenceManager
Use LocationManager.getLastPosition() in GeofenceManager instead of
keeping track of it manually. Keeping track of it in GeofenceManager
doesn't handle the case where we install a fence, and cross it just
after that based on the last position before we installed the fence.
Also shuffle around some code in LocationManagerService to remember the
last position even if there are no UpdateRecords. This is useful in the
GeofenceManager for example.
Bug: 7047435
Change-Id: Ia8acc32e357ecc2e1bd689432a5beb1ea7dcd1c7
| -rw-r--r-- | services/java/com/android/server/LocationManagerService.java | 7 | ||||
| -rw-r--r-- | services/java/com/android/server/location/GeofenceManager.java | 6 |
2 files changed, 7 insertions, 6 deletions
diff --git a/services/java/com/android/server/LocationManagerService.java b/services/java/com/android/server/LocationManagerService.java index 0087b57456d2..e73d599297aa 100644 --- a/services/java/com/android/server/LocationManagerService.java +++ b/services/java/com/android/server/LocationManagerService.java @@ -1414,9 +1414,8 @@ public class LocationManagerService extends ILocationManager.Stub implements Run long now = SystemClock.elapsedRealtime(); String provider = (passive ? LocationManager.PASSIVE_PROVIDER : location.getProvider()); - ArrayList<UpdateRecord> records = mRecordsByProvider.get(provider); - if (records == null || records.size() == 0) return; + // Skip if the provider is unknown. LocationProviderInterface p = mProvidersByName.get(provider); if (p == null) return; @@ -1437,6 +1436,10 @@ public class LocationManagerService extends ILocationManager.Stub implements Run } lastLocation.set(location); + // Skip if there are no UpdateRecords for this provider. + ArrayList<UpdateRecord> records = mRecordsByProvider.get(provider); + if (records == null || records.size() == 0) return; + // Fetch coarse location Location coarseLocation = null; if (noGPSLocation != null && !noGPSLocation.equals(lastNoGPSLocation)) { diff --git a/services/java/com/android/server/location/GeofenceManager.java b/services/java/com/android/server/location/GeofenceManager.java index 26d9c1555774..d04d2f32d46e 100644 --- a/services/java/com/android/server/location/GeofenceManager.java +++ b/services/java/com/android/server/location/GeofenceManager.java @@ -58,7 +58,6 @@ public class GeofenceManager implements LocationListener, PendingIntent.OnFinish private Object mLock = new Object(); // access to members below is synchronized on mLock - private Location mLastLocation; private List<GeofenceState> mFences = new LinkedList<GeofenceState>(); public GeofenceManager(Context context, LocationBlacklist blacklist) { @@ -77,7 +76,8 @@ public class GeofenceManager implements LocationListener, PendingIntent.OnFinish public void addFence(LocationRequest request, Geofence geofence, PendingIntent intent, int uid, String packageName) { - GeofenceState state = new GeofenceState(geofence, mLastLocation, + Location lastLocation = mLocationManager.getLastLocation(); + GeofenceState state = new GeofenceState(geofence, lastLocation, request.getExpireAt(), packageName, intent); synchronized (mLock) { @@ -146,8 +146,6 @@ public class GeofenceManager implements LocationListener, PendingIntent.OnFinish List<PendingIntent> exitIntents = new LinkedList<PendingIntent>(); synchronized (mLock) { - mLastLocation = location; - removeExpiredFencesLocked(); for (GeofenceState state : mFences) { |