summaryrefslogtreecommitdiffstats
path: root/services/core/java/com/android/server/content/SyncOperation.java
diff options
context:
space:
mode:
authorMatthew Williams <mjwilliams@google.com>2014-03-21 21:59:07 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-03-21 21:59:07 +0000
commitcde7086b900fd192a8e389f62ab5007d351d86b8 (patch)
tree8b82f7dd61c65e1c677a3664ddc4deaae53362d9 /services/core/java/com/android/server/content/SyncOperation.java
parent717e0f5db7161ddfff98f21fe1cdb2a3b1a6c8b7 (diff)
parent6428046767ee4195617fb41b5639eefa2ca7a939 (diff)
downloadframeworks_base-cde7086b900fd192a8e389f62ab5007d351d86b8.zip
frameworks_base-cde7086b900fd192a8e389f62ab5007d351d86b8.tar.gz
frameworks_base-cde7086b900fd192a8e389f62ab5007d351d86b8.tar.bz2
Merge "Downgrade expedited to normal on reschedule."
Diffstat (limited to 'services/core/java/com/android/server/content/SyncOperation.java')
-rw-r--r--services/core/java/com/android/server/content/SyncOperation.java74
1 files changed, 36 insertions, 38 deletions
diff --git a/services/core/java/com/android/server/content/SyncOperation.java b/services/core/java/com/android/server/content/SyncOperation.java
index 5233014..9a4abce 100644
--- a/services/core/java/com/android/server/content/SyncOperation.java
+++ b/services/core/java/com/android/server/content/SyncOperation.java
@@ -65,17 +65,18 @@ public class SyncOperation implements Comparable {
/** Why this sync was kicked off. {@link #REASON_NAMES} */
public final int reason;
/** Where this sync was initiated. */
- public int syncSource;
+ public final int syncSource;
public final boolean allowParallelSyncs;
- public Bundle extras;
public final String key;
- public boolean expedited;
+ /** Internal boolean to avoid reading a bundle everytime we want to compare operations. */
+ private final boolean expedited;
+ public Bundle extras;
/** Bare-bones version of this operation that is persisted across reboots. */
public SyncStorageEngine.PendingOperation pendingOperation;
/** Elapsed real time in millis at which to run this sync. */
public long latestRunTime;
/** Set by the SyncManager in order to delay retries. */
- public Long backoff;
+ public long backoff;
/** Specified by the adapter to delay subsequent sync operations. */
public long delayUntil;
/**
@@ -92,61 +93,58 @@ public class SyncOperation implements Comparable {
public SyncOperation(Account account, int userId, int reason, int source, String provider,
Bundle extras, long runTimeFromNow, long flexTime, long backoff,
long delayUntil, boolean allowParallelSyncs) {
- this.target = new SyncStorageEngine.EndPoint(account, provider, userId);
- this.reason = reason;
- this.allowParallelSyncs = allowParallelSyncs;
- this.key = initialiseOperation(this.target, source, extras, runTimeFromNow, flexTime,
- backoff, delayUntil);
+ this(new SyncStorageEngine.EndPoint(account, provider, userId),
+ reason, source, extras, runTimeFromNow, flexTime, backoff, delayUntil,
+ allowParallelSyncs);
}
public SyncOperation(ComponentName service, int userId, int reason, int source,
Bundle extras, long runTimeFromNow, long flexTime, long backoff,
long delayUntil) {
- this.target = new SyncStorageEngine.EndPoint(service, userId);
- // Default to true for sync service. The service itself decides how to handle this.
- this.allowParallelSyncs = true;
- this.reason = reason;
- this.key =
- initialiseOperation(this.target,
- source, extras, runTimeFromNow, flexTime, backoff, delayUntil);
- }
-
- /** Used to reschedule a sync at a new point in time. */
- SyncOperation(SyncOperation other, long newRunTimeFromNow) {
- this.target = other.target;
- this.reason = other.reason;
- this.expedited = other.expedited;
- this.allowParallelSyncs = other.allowParallelSyncs;
- // re-use old flex, but only
- long newFlexTime = Math.min(other.flexTime, newRunTimeFromNow);
- this.key =
- initialiseOperation(this.target,
- other.syncSource, other.extras,
- newRunTimeFromNow /* runTimeFromNow*/,
- newFlexTime /* flexTime */,
- other.backoff,
- 0L /* delayUntil */);
+ this(new SyncStorageEngine.EndPoint(service, userId), reason, source, extras,
+ runTimeFromNow, flexTime, backoff, delayUntil, true /* allowParallelSyncs */);
}
- private String initialiseOperation(SyncStorageEngine.EndPoint info, int source, Bundle extras,
- long runTimeFromNow, long flexTime, long backoff, long delayUntil) {
+ private SyncOperation(SyncStorageEngine.EndPoint info, int reason, int source, Bundle extras,
+ long runTimeFromNow, long flexTime, long backoff, long delayUntil,
+ boolean allowParallelSyncs) {
+ this.target = info;
+ this.reason = reason;
this.syncSource = source;
this.extras = new Bundle(extras);
cleanBundle(this.extras);
this.delayUntil = delayUntil;
this.backoff = backoff;
+ this.allowParallelSyncs = allowParallelSyncs;
final long now = SystemClock.elapsedRealtime();
- if (runTimeFromNow < 0 || isExpedited()) {
+ // Set expedited based on runTimeFromNow. The SyncManager specifies whether the op is
+ // expedited (Not done solely based on bundle).
+ if (runTimeFromNow < 0) {
this.expedited = true;
+ // Sanity check: Will always be true.
+ if (!this.extras.getBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, false)) {
+ this.extras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
+ }
this.latestRunTime = now;
this.flexTime = 0;
} else {
this.expedited = false;
+ this.extras.remove(ContentResolver.SYNC_EXTRAS_EXPEDITED);
this.latestRunTime = now + runTimeFromNow;
this.flexTime = flexTime;
}
updateEffectiveRunTime();
- return toKey(info, this.extras);
+ this.key = toKey(info, this.extras);
+ }
+
+ /** Used to reschedule a sync at a new point in time. */
+ public SyncOperation(SyncOperation other, long newRunTimeFromNow) {
+ this(other.target, other.reason, other.syncSource, new Bundle(other.extras),
+ newRunTimeFromNow,
+ 0L /* In back-off so no flex */,
+ other.backoff,
+ other.delayUntil,
+ other.allowParallelSyncs);
}
public boolean matchesAuthority(SyncOperation other) {
@@ -264,7 +262,7 @@ public class SyncOperation implements Comparable {
}
public boolean isExpedited() {
- return extras.getBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, false) || expedited;
+ return expedited;
}
public boolean ignoreBackoff() {