am cc220364: am 685cc8c7: Merge "Decrement number of updates in LocationRequest" into jb-mr1-dev

* commit 'cc2203649457985cdcf9e4d3336ed2da5aa657d2':
  Decrement number of updates in LocationRequest
This commit is contained in:
Laurent Tu
2012-11-02 15:21:51 -07:00
committed by Android Git Automerger

View File

@@ -224,7 +224,7 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
// listen for settings changes // listen for settings changes
mContext.getContentResolver().registerContentObserver( mContext.getContentResolver().registerContentObserver(
Settings.Secure.getUriFor(Settings.Secure.LOCATION_PROVIDERS_ALLOWED), true, Settings.Secure.getUriFor(Settings.Secure.LOCATION_PROVIDERS_ALLOWED), true,
new ContentObserver(mLocationHandler) { new ContentObserver(mLocationHandler) {
@Override @Override
public void onChange(boolean selfChange) { public void onChange(boolean selfChange) {
@@ -1540,7 +1540,8 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
} }
private static boolean shouldBroadcastSafe(Location loc, Location lastLoc, UpdateRecord record) { private static boolean shouldBroadcastSafe(
Location loc, Location lastLoc, UpdateRecord record, long now) {
// Always broadcast the first update // Always broadcast the first update
if (lastLoc == null) { if (lastLoc == null) {
return true; return true;
@@ -1561,6 +1562,16 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
} }
} }
// Check whether sufficient number of udpates is left
if (record.mRequest.getNumUpdates() <= 0) {
return false;
}
// Check whether the expiry date has passed
if (record.mRequest.getExpireAt() < now) {
return false;
}
return true; return true;
} }
@@ -1640,7 +1651,7 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
} }
if (notifyLocation != null) { if (notifyLocation != null) {
Location lastLoc = r.mLastFixBroadcast; Location lastLoc = r.mLastFixBroadcast;
if ((lastLoc == null) || shouldBroadcastSafe(notifyLocation, lastLoc, r)) { if ((lastLoc == null) || shouldBroadcastSafe(notifyLocation, lastLoc, r, now)) {
if (lastLoc == null) { if (lastLoc == null) {
lastLoc = new Location(notifyLocation); lastLoc = new Location(notifyLocation);
r.mLastFixBroadcast = lastLoc; r.mLastFixBroadcast = lastLoc;
@@ -1651,6 +1662,7 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
Slog.w(TAG, "RemoteException calling onLocationChanged on " + receiver); Slog.w(TAG, "RemoteException calling onLocationChanged on " + receiver);
receiverDead = true; receiverDead = true;
} }
r.mRequest.decrementNumUpdates();
} }
} }
@@ -1666,7 +1678,7 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
} }
// track expired records // track expired records
if (r.mRequest.getNumUpdates() == 0 || r.mRequest.getExpireAt() < now) { if (r.mRequest.getNumUpdates() <= 0 || r.mRequest.getExpireAt() < now) {
if (deadUpdateRecords == null) { if (deadUpdateRecords == null) {
deadUpdateRecords = new ArrayList<UpdateRecord>(); deadUpdateRecords = new ArrayList<UpdateRecord>();
} }