Prevent overflow in LocationRequest.setExpireIn(), for example,
when we pass in Long.MAX_VALUE.
Bug:
7047435
Change-Id: Ie56928a59fb387173fbd3887c0ef9aede00f8152
* @return the same object, so that setters can be chained
*/
public LocationRequest setExpireIn(long millis) {
- mExpireAt = millis + SystemClock.elapsedRealtime();
+ long elapsedRealtime = SystemClock.elapsedRealtime();
+
+ // Check for > Long.MAX_VALUE overflow (elapsedRealtime > 0):
+ if (millis > Long.MAX_VALUE - elapsedRealtime) {
+ mExpireAt = Long.MAX_VALUE;
+ } else {
+ mExpireAt = millis + elapsedRealtime;
+ }
+
if (mExpireAt < 0) mExpireAt = 0;
return this;
}