Skip to content

Commit 60ec50a

Browse files
committed
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
1 parent dfc8e79 commit 60ec50a

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

services/java/com/android/server/LocationManagerService.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,9 +1414,8 @@ private void handleLocationChangedLocked(Location location, boolean passive) {
14141414

14151415
long now = SystemClock.elapsedRealtime();
14161416
String provider = (passive ? LocationManager.PASSIVE_PROVIDER : location.getProvider());
1417-
ArrayList<UpdateRecord> records = mRecordsByProvider.get(provider);
1418-
if (records == null || records.size() == 0) return;
14191417

1418+
// Skip if the provider is unknown.
14201419
LocationProviderInterface p = mProvidersByName.get(provider);
14211420
if (p == null) return;
14221421

@@ -1437,6 +1436,10 @@ private void handleLocationChangedLocked(Location location, boolean passive) {
14371436
}
14381437
lastLocation.set(location);
14391438

1439+
// Skip if there are no UpdateRecords for this provider.
1440+
ArrayList<UpdateRecord> records = mRecordsByProvider.get(provider);
1441+
if (records == null || records.size() == 0) return;
1442+
14401443
// Fetch coarse location
14411444
Location coarseLocation = null;
14421445
if (noGPSLocation != null && !noGPSLocation.equals(lastNoGPSLocation)) {

services/java/com/android/server/location/GeofenceManager.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public class GeofenceManager implements LocationListener, PendingIntent.OnFinish
5858
private Object mLock = new Object();
5959

6060
// access to members below is synchronized on mLock
61-
private Location mLastLocation;
6261
private List<GeofenceState> mFences = new LinkedList<GeofenceState>();
6362

6463
public GeofenceManager(Context context, LocationBlacklist blacklist) {
@@ -77,7 +76,8 @@ public GeofenceManager(Context context, LocationBlacklist blacklist) {
7776

7877
public void addFence(LocationRequest request, Geofence geofence, PendingIntent intent, int uid,
7978
String packageName) {
80-
GeofenceState state = new GeofenceState(geofence, mLastLocation,
79+
Location lastLocation = mLocationManager.getLastLocation();
80+
GeofenceState state = new GeofenceState(geofence, lastLocation,
8181
request.getExpireAt(), packageName, intent);
8282

8383
synchronized (mLock) {
@@ -146,8 +146,6 @@ private void processLocation(Location location) {
146146
List<PendingIntent> exitIntents = new LinkedList<PendingIntent>();
147147

148148
synchronized (mLock) {
149-
mLastLocation = location;
150-
151149
removeExpiredFencesLocked();
152150

153151
for (GeofenceState state : mFences) {

0 commit comments

Comments
 (0)