diff options
author | Wei Liu <luciferleo@google.com> | 2015-06-26 22:58:31 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-06-26 22:58:31 +0000 |
commit | 0adc5f3794d1800f8cc00ccdeebb810a4bdb2c87 (patch) | |
tree | 320550d174364586a3e28017f6ac10514747e4ef | |
parent | 52d82d7ea920a02eba8514a68c5da9e286e4c56b (diff) | |
parent | 834672285050812d08cd173559382bc5c3e9800a (diff) | |
download | frameworks_base-0adc5f3794d1800f8cc00ccdeebb810a4bdb2c87.zip frameworks_base-0adc5f3794d1800f8cc00ccdeebb810a4bdb2c87.tar.gz frameworks_base-0adc5f3794d1800f8cc00ccdeebb810a4bdb2c87.tar.bz2 |
am 83467228: am 6f6326bc: Implement a exponential backoff for NTP time and XTRA data retry.
* commit '834672285050812d08cd173559382bc5c3e9800a':
Implement a exponential backoff for NTP time and XTRA data retry.
-rw-r--r-- | services/core/java/com/android/server/location/GpsLocationProvider.java | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/location/GpsLocationProvider.java b/services/core/java/com/android/server/location/GpsLocationProvider.java index 3850306..45a4829 100644 --- a/services/core/java/com/android/server/location/GpsLocationProvider.java +++ b/services/core/java/com/android/server/location/GpsLocationProvider.java @@ -281,8 +281,16 @@ public class GpsLocationProvider implements LocationProviderInterface { // current setting 24 hours private static final long NTP_INTERVAL = 24*60*60*1000; // how long to wait if we have a network error in NTP or XTRA downloading + // the initial value of the exponential backoff // current setting - 5 minutes private static final long RETRY_INTERVAL = 5*60*1000; + // how long to wait if we have a network error in NTP or XTRA downloading + // the max value of the exponential backoff + // current setting - 4 hours + private static final long MAX_RETRY_INTERVAL = 4*60*60*1000; + + private BackOff mNtpBackOff = new BackOff(RETRY_INTERVAL, MAX_RETRY_INTERVAL); + private BackOff mXtraBackOff = new BackOff(RETRY_INTERVAL, MAX_RETRY_INTERVAL); // true if we are enabled, protected by this private boolean mEnabled; @@ -832,9 +840,10 @@ public class GpsLocationProvider implements LocationProviderInterface { native_inject_time(time, timeReference, (int) certainty); delay = NTP_INTERVAL; + mNtpBackOff.reset(); } else { if (DEBUG) Log.d(TAG, "requestTime failed"); - delay = RETRY_INTERVAL; + delay = mNtpBackOff.nextBackoffMillis(); } sendMessage(INJECT_NTP_TIME_FINISHED, 0, null); @@ -875,6 +884,7 @@ public class GpsLocationProvider implements LocationProviderInterface { Log.d(TAG, "calling native_inject_xtra_data"); } native_inject_xtra_data(data, data.length); + mXtraBackOff.reset(); } sendMessage(DOWNLOAD_XTRA_DATA_FINISHED, 0, null); @@ -882,7 +892,8 @@ public class GpsLocationProvider implements LocationProviderInterface { if (data == null) { // try again later // since this is delayed and not urgent we do not hold a wake lock here - mHandler.sendEmptyMessageDelayed(DOWNLOAD_XTRA_DATA, RETRY_INTERVAL); + mHandler.sendEmptyMessageDelayed(DOWNLOAD_XTRA_DATA, + mXtraBackOff.nextBackoffMillis()); } // release wake lock held by task @@ -2190,6 +2201,36 @@ public class GpsLocationProvider implements LocationProviderInterface { pw.append(s); } + /** + * A simple implementation of exponential backoff. + */ + private static final class BackOff { + private static final int MULTIPLIER = 2; + private final long mInitIntervalMillis; + private final long mMaxIntervalMillis; + private long mCurrentIntervalMillis; + + public BackOff(long initIntervalMillis, long maxIntervalMillis) { + mInitIntervalMillis = initIntervalMillis; + mMaxIntervalMillis = maxIntervalMillis; + + mCurrentIntervalMillis = mInitIntervalMillis / MULTIPLIER; + } + + public long nextBackoffMillis() { + if (mCurrentIntervalMillis > mMaxIntervalMillis) { + return mMaxIntervalMillis; + } + + mCurrentIntervalMillis *= MULTIPLIER; + return mCurrentIntervalMillis; + } + + public void reset() { + mCurrentIntervalMillis = mInitIntervalMillis / MULTIPLIER; + } + } + // for GPS SV statistics private static final int MAX_SVS = 32; private static final int EPHEMERIS_MASK = 0; |