summaryrefslogtreecommitdiffstats
path: root/common/java
diff options
context:
space:
mode:
authorDan Egnor <egnor@google.com>2010-02-03 17:01:10 -0800
committerDan Egnor <egnor@google.com>2010-02-03 18:28:08 -0800
commit2991425379efd0bc29bce6cd718e5833cc6aa59b (patch)
tree8972322d9b98079720252b53bac986f4d581a27d /common/java
parentfa6bc84e01c061ded1b9ab11a82cbbaac2843f73 (diff)
downloadframeworks_base-2991425379efd0bc29bce6cd718e5833cc6aa59b.zip
frameworks_base-2991425379efd0bc29bce6cd718e5833cc6aa59b.tar.gz
frameworks_base-2991425379efd0bc29bce6cd718e5833cc6aa59b.tar.bz2
Add ability to parse HTTP-format moratorium times
(since pretty much every user wants this).
Diffstat (limited to 'common/java')
-rw-r--r--common/java/com/android/common/OperationScheduler.java24
1 files changed, 23 insertions, 1 deletions
diff --git a/common/java/com/android/common/OperationScheduler.java b/common/java/com/android/common/OperationScheduler.java
index 71b22ce..c7b12d3 100644
--- a/common/java/com/android/common/OperationScheduler.java
+++ b/common/java/com/android/common/OperationScheduler.java
@@ -192,7 +192,6 @@ public class OperationScheduler {
/**
* Forbid any operations until after a certain (absolute) time.
- * Commonly used when a server returns a "Retry-After:" type directive.
* Limited by {@link #Options.maxMoratoriumMillis}.
*
* @param millis wall clock time ({@link System#currentTimeMillis()}) to
@@ -206,6 +205,29 @@ public class OperationScheduler {
}
/**
+ * Forbid any operations until after a certain time, as specified in
+ * the format used by the HTTP "Retry-After" header.
+ * Limited by {@link #Options.maxMoratoriumMillis}.
+ *
+ * @param retryAfter moratorium time in HTTP format
+ * @return true if a time was successfully parsed
+ */
+ public boolean setMoratoriumTimeHttp(String retryAfter) {
+ try {
+ long ms = Long.valueOf(retryAfter) * 1000;
+ setMoratoriumTimeMillis(ms + System.currentTimeMillis());
+ return true;
+ } catch (NumberFormatException nfe) {
+ try {
+ setMoratoriumTimeMillis(HttpDateTime.parse(retryAfter));
+ return true;
+ } catch (IllegalArgumentException iae) {
+ return false;
+ }
+ }
+ }
+
+ /**
* Enable or disable all operations. When disabled, all calls to
* {@link #getNextTimeMillis()} return {@link Long#MAX_VALUE}.
* Commonly used when data network availability goes up and down.