1 package com.android.server.location; 2 3 /** 4 * A simple implementation of exponential backoff. 5 */ 6 class ExponentialBackOff { 7 private static final int MULTIPLIER = 2; 8 private final long mInitIntervalMillis; 9 private final long mMaxIntervalMillis; 10 private long mCurrentIntervalMillis; 11 ExponentialBackOff(long initIntervalMillis, long maxIntervalMillis)12 ExponentialBackOff(long initIntervalMillis, long maxIntervalMillis) { 13 mInitIntervalMillis = initIntervalMillis; 14 mMaxIntervalMillis = maxIntervalMillis; 15 16 mCurrentIntervalMillis = mInitIntervalMillis / MULTIPLIER; 17 } 18 nextBackoffMillis()19 long nextBackoffMillis() { 20 if (mCurrentIntervalMillis > mMaxIntervalMillis) { 21 return mMaxIntervalMillis; 22 } 23 24 mCurrentIntervalMillis *= MULTIPLIER; 25 return mCurrentIntervalMillis; 26 } 27 reset()28 void reset() { 29 mCurrentIntervalMillis = mInitIntervalMillis / MULTIPLIER; 30 } 31 } 32 33