diff options
author | Dan Egnor <egnor@google.com> | 2010-02-17 17:07:01 -0800 |
---|---|---|
committer | Dan Egnor <egnor@google.com> | 2010-02-17 17:07:01 -0800 |
commit | 8a2e0111958b9f6b665d0ed9a6d8bceb9d8fa31a (patch) | |
tree | b35fbfc302a46cd9331d511d5b88c96d0ac5126b /common/java | |
parent | 6a70d7d1e28bd0b98d03e7ecab3fd08ea5973e34 (diff) | |
download | frameworks_base-8a2e0111958b9f6b665d0ed9a6d8bceb9d8fa31a.zip frameworks_base-8a2e0111958b9f6b665d0ed9a6d8bceb9d8fa31a.tar.gz frameworks_base-8a2e0111958b9f6b665d0ed9a6d8bceb9d8fa31a.tar.bz2 |
Add some useful methods to OperationScheduler to inquire into
the history, in case you want to second-guess its scheduling.
Diffstat (limited to 'common/java')
-rw-r--r-- | common/java/com/android/common/OperationScheduler.java | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/common/java/com/android/common/OperationScheduler.java b/common/java/com/android/common/OperationScheduler.java index c7b12d3..0c7ca83 100644 --- a/common/java/com/android/common/OperationScheduler.java +++ b/common/java/com/android/common/OperationScheduler.java @@ -158,12 +158,35 @@ public class OperationScheduler { time = Math.max(time, moratoriumTimeMillis); } time = Math.max(time, lastSuccessTimeMillis + options.minTriggerMillis); - time = Math.max(time, lastErrorTimeMillis + options.backoffFixedMillis + - options.backoffIncrementalMillis * errorCount); + if (errorCount > 0) { + time = Math.max(time, lastErrorTimeMillis + options.backoffFixedMillis + + options.backoffIncrementalMillis * errorCount); + } return time; } /** + * Return the last time the operation completed. Does not modify any state. + * + * @return the wall clock time when {@link #onSuccess()} was last called. + */ + public long getLastSuccessTimeMillis() { + return mStorage.getLong(PREFIX + "lastSuccessTimeMillis", 0); + } + + /** + * Return the last time the operation was attempted. Does not modify any state. + * + * @return the wall clock time when {@link #onSuccess()} or {@link + * #onTransientError()} was last called. + */ + public long getLastAttemptTimeMillis() { + return Math.max( + mStorage.getLong(PREFIX + "lastSuccessTimeMillis", 0), + mStorage.getLong(PREFIX + "lastErrorTimeMillis", 0)); + } + + /** * Fetch a {@link SharedPreferences} property, but force it to be before * a certain time, updating the value if necessary. This is to recover * gracefully from clock rollbacks which could otherwise strand our timers. @@ -273,9 +296,7 @@ public class OperationScheduler { * where there is reason to hope things might start working better. */ public void resetTransientError() { - mStorage.edit() - .remove(PREFIX + "lastErrorTimeMillis") - .remove(PREFIX + "errorCount").commit(); + mStorage.edit().remove(PREFIX + "errorCount").commit(); } /** |