@@ -224,7 +224,7 @@ private void init() {
224224
225225 // listen for settings changes
226226 mContext .getContentResolver ().registerContentObserver (
227- Settings .Secure .getUriFor (Settings .Secure .LOCATION_PROVIDERS_ALLOWED ), true ,
227+ Settings .Secure .getUriFor (Settings .Secure .LOCATION_PROVIDERS_ALLOWED ), true ,
228228 new ContentObserver (mLocationHandler ) {
229229 @ Override
230230 public void onChange (boolean selfChange ) {
@@ -1540,7 +1540,8 @@ public void reportLocation(Location location, boolean passive) {
15401540 }
15411541
15421542
1543- private static boolean shouldBroadcastSafe (Location loc , Location lastLoc , UpdateRecord record ) {
1543+ private static boolean shouldBroadcastSafe (
1544+ Location loc , Location lastLoc , UpdateRecord record , long now ) {
15441545 // Always broadcast the first update
15451546 if (lastLoc == null ) {
15461547 return true ;
@@ -1561,6 +1562,16 @@ private static boolean shouldBroadcastSafe(Location loc, Location lastLoc, Updat
15611562 }
15621563 }
15631564
1565+ // Check whether sufficient number of udpates is left
1566+ if (record .mRequest .getNumUpdates () <= 0 ) {
1567+ return false ;
1568+ }
1569+
1570+ // Check whether the expiry date has passed
1571+ if (record .mRequest .getExpireAt () < now ) {
1572+ return false ;
1573+ }
1574+
15641575 return true ;
15651576 }
15661577
@@ -1640,7 +1651,7 @@ private void handleLocationChangedLocked(Location location, boolean passive) {
16401651 }
16411652 if (notifyLocation != null ) {
16421653 Location lastLoc = r .mLastFixBroadcast ;
1643- if ((lastLoc == null ) || shouldBroadcastSafe (notifyLocation , lastLoc , r )) {
1654+ if ((lastLoc == null ) || shouldBroadcastSafe (notifyLocation , lastLoc , r , now )) {
16441655 if (lastLoc == null ) {
16451656 lastLoc = new Location (notifyLocation );
16461657 r .mLastFixBroadcast = lastLoc ;
@@ -1651,6 +1662,7 @@ private void handleLocationChangedLocked(Location location, boolean passive) {
16511662 Slog .w (TAG , "RemoteException calling onLocationChanged on " + receiver );
16521663 receiverDead = true ;
16531664 }
1665+ r .mRequest .decrementNumUpdates ();
16541666 }
16551667 }
16561668
@@ -1666,7 +1678,7 @@ private void handleLocationChangedLocked(Location location, boolean passive) {
16661678 }
16671679
16681680 // track expired records
1669- if (r .mRequest .getNumUpdates () = = 0 || r .mRequest .getExpireAt () < now ) {
1681+ if (r .mRequest .getNumUpdates () < = 0 || r .mRequest .getExpireAt () < now ) {
16701682 if (deadUpdateRecords == null ) {
16711683 deadUpdateRecords = new ArrayList <UpdateRecord >();
16721684 }
0 commit comments