diff options
| author | 2019-11-06 02:17:43 +0000 | |
|---|---|---|
| committer | 2019-11-06 02:17:43 +0000 | |
| commit | d838847e92f94bcd46aadcf787ac3dfc9b17e601 (patch) | |
| tree | eaa51f2827e91bc27c8b9d23690365ec45a685f4 | |
| parent | abd5923922e271e28cc0a861fa03841336410468 (diff) | |
| parent | 95768ce2771b7a2470c9b7b15ad78f04397857cc (diff) | |
Merge "Fix determining request expiration time"
3 files changed, 23 insertions, 16 deletions
diff --git a/location/java/android/location/LocationRequest.java b/location/java/android/location/LocationRequest.java index 3abd2c2144e1..ca8f2ac82e94 100644 --- a/location/java/android/location/LocationRequest.java +++ b/location/java/android/location/LocationRequest.java @@ -505,6 +505,23 @@ public final class LocationRequest implements Parcelable { } /** + * Returns the realtime at which this request expires, taking into account both + * {@link #setExpireAt(long)} and {@link #setExpireIn(long)} relative to the given realtime. + * + * @hide + */ + public long getExpirationRealtimeMs(long startRealtimeMs) { + long expirationRealtimeMs; + // Check for > Long.MAX_VALUE overflow (elapsedRealtime > 0): + if (mExpireIn > Long.MAX_VALUE - startRealtimeMs) { + expirationRealtimeMs = Long.MAX_VALUE; + } else { + expirationRealtimeMs = startRealtimeMs + mExpireIn; + } + return Math.min(expirationRealtimeMs, mExpireAt); + } + + /** * Set the number of location updates. * * <p>By default locations are continuously updated until the request is explicitly diff --git a/services/core/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/LocationManagerService.java index 593faf11c6f1..e1f65979bec3 100644 --- a/services/core/java/com/android/server/LocationManagerService.java +++ b/services/core/java/com/android/server/LocationManagerService.java @@ -2005,23 +2005,13 @@ public class LocationManagerService extends ILocationManager.Stub { private boolean mIsForegroundUid; private Location mLastFixBroadcast; private Throwable mStackTrace; // for debugging only + private long mExpirationRealtimeMs; /** * Note: must be constructed with lock held. */ private UpdateRecord(String provider, LocationRequest request, Receiver receiver) { - // translate expireIn value into expireAt - long elapsedRealtime = SystemClock.elapsedRealtime(); - long expireAt; - // Check for > Long.MAX_VALUE overflow (elapsedRealtime > 0): - if (request.getExpireIn() > Long.MAX_VALUE - elapsedRealtime) { - expireAt = Long.MAX_VALUE; - } else { - expireAt = Math.max(request.getExpireIn() + elapsedRealtime, 0); - } - request.setExpireAt(Math.min(request.getExpireAt(), expireAt)); - request.setExpireIn(Long.MAX_VALUE); - + mExpirationRealtimeMs = request.getExpirationRealtimeMs(SystemClock.elapsedRealtime()); mProvider = provider; mRealRequest = request; mRequest = request; @@ -2883,7 +2873,7 @@ public class LocationManagerService extends ILocationManager.Stub { } // Check whether the expiry date has passed - return record.mRealRequest.getExpireAt() >= now; + return record.mExpirationRealtimeMs >= now; } @GuardedBy("mLock") @@ -3015,7 +3005,7 @@ public class LocationManagerService extends ILocationManager.Stub { } // track expired records - if (r.mRealRequest.getNumUpdates() <= 0 || r.mRealRequest.getExpireAt() < now) { + if (r.mRealRequest.getNumUpdates() <= 0 || r.mExpirationRealtimeMs < now) { // notify the client it can remove this listener r.mReceiver.callRemovedLocked(); if (deadUpdateRecords == null) { diff --git a/services/core/java/com/android/server/location/GeofenceManager.java b/services/core/java/com/android/server/location/GeofenceManager.java index c970788a95c4..81c06d7125f9 100644 --- a/services/core/java/com/android/server/location/GeofenceManager.java +++ b/services/core/java/com/android/server/location/GeofenceManager.java @@ -133,8 +133,8 @@ public class GeofenceManager implements LocationListener, PendingIntent.OnFinish } GeofenceState state = new GeofenceState(geofence, - request.getExpireAt(), allowedResolutionLevel, uid, packageName, featureId, - listenerIdentifier, intent); + request.getExpirationRealtimeMs(SystemClock.elapsedRealtime()), + allowedResolutionLevel, uid, packageName, featureId, listenerIdentifier, intent); synchronized (mLock) { // first make sure it doesn't already exist for (int i = mFences.size() - 1; i >= 0; i--) { |