summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorWei Liu <luciferleo@google.com>2015-06-24 23:47:50 -0700
committerWei Liu <luciferleo@google.com>2015-06-25 21:12:58 -0700
commit6f6326bc75be652a0b88b73fd6e0b73dbe2fabb6 (patch)
tree4e17fcbacbf8d11bf868bb247798c103abf15c35 /services
parent001df9ca900f3098222a4920a0048d2eb947bd4e (diff)
downloadframeworks_base-6f6326bc75be652a0b88b73fd6e0b73dbe2fabb6.zip
frameworks_base-6f6326bc75be652a0b88b73fd6e0b73dbe2fabb6.tar.gz
frameworks_base-6f6326bc75be652a0b88b73fd6e0b73dbe2fabb6.tar.bz2
Implement a exponential backoff for NTP time and XTRA data retry.
b/21904128 Change-Id: I9fc8917eed3065ff0a4946c5a3bdecb9e93da19d
Diffstat (limited to 'services')
-rw-r--r--services/core/java/com/android/server/location/GpsLocationProvider.java49
1 files changed, 43 insertions, 6 deletions
diff --git a/services/core/java/com/android/server/location/GpsLocationProvider.java b/services/core/java/com/android/server/location/GpsLocationProvider.java
index 621e1bd..ba72987 100644
--- a/services/core/java/com/android/server/location/GpsLocationProvider.java
+++ b/services/core/java/com/android/server/location/GpsLocationProvider.java
@@ -22,10 +22,8 @@ import com.android.internal.location.GpsNetInitiatedHandler;
import com.android.internal.location.GpsNetInitiatedHandler.GpsNiNotification;
import com.android.internal.location.ProviderProperties;
import com.android.internal.location.ProviderRequest;
-import com.android.internal.R;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
-import com.android.internal.telephony.TelephonyIntents;
import android.app.AlarmManager;
import android.app.AppOpsManager;
@@ -72,7 +70,6 @@ import android.provider.Settings;
import android.provider.Telephony.Carriers;
import android.provider.Telephony.Sms.Intents;
import android.telephony.SmsMessage;
-import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
import android.telephony.TelephonyManager;
@@ -91,7 +88,6 @@ import java.io.StringReader;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;
-import java.util.List;
import java.util.Map.Entry;
import java.util.Properties;
@@ -283,8 +279,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;
@@ -877,9 +881,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);
@@ -920,6 +925,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);
@@ -927,7 +933,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
@@ -2147,6 +2154,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;