am bb87ac7f: DO NOT MERGE: Downgrade expedited to normal on reschedule.
* commit 'bb87ac7f9733ca9b490cb34e8a675dba083a57b7': DO NOT MERGE: Downgrade expedited to normal on reschedule.
This commit is contained in:
@@ -2352,7 +2352,7 @@ public class SyncManager {
|
|||||||
Log.v(TAG, "canceling and rescheduling sync since an initialization "
|
Log.v(TAG, "canceling and rescheduling sync since an initialization "
|
||||||
+ "takes higher priority, " + conflict);
|
+ "takes higher priority, " + conflict);
|
||||||
}
|
}
|
||||||
} else if (candidate.expedited && !conflict.mSyncOperation.expedited
|
} else if (candidate.isExpedited() && !conflict.mSyncOperation.isExpedited()
|
||||||
&& (candidateIsInitialization
|
&& (candidateIsInitialization
|
||||||
== conflict.mSyncOperation.isInitialization())) {
|
== conflict.mSyncOperation.isInitialization())) {
|
||||||
toReschedule = conflict;
|
toReschedule = conflict;
|
||||||
|
|||||||
@@ -66,7 +66,8 @@ public class SyncOperation implements Comparable {
|
|||||||
public final boolean allowParallelSyncs;
|
public final boolean allowParallelSyncs;
|
||||||
public Bundle extras;
|
public Bundle extras;
|
||||||
public final String key;
|
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 SyncStorageEngine.PendingOperation pendingOperation;
|
public SyncStorageEngine.PendingOperation pendingOperation;
|
||||||
/** Elapsed real time in millis at which to run this sync. */
|
/** Elapsed real time in millis at which to run this sync. */
|
||||||
public long latestRunTime;
|
public long latestRunTime;
|
||||||
@@ -79,7 +80,7 @@ public class SyncOperation implements Comparable {
|
|||||||
* Depends on max(backoff, latestRunTime, and delayUntil).
|
* Depends on max(backoff, latestRunTime, and delayUntil).
|
||||||
*/
|
*/
|
||||||
public long effectiveRunTime;
|
public long effectiveRunTime;
|
||||||
/** Amount of time before {@link effectiveRunTime} from which this sync can run. */
|
/** Amount of time before {@link #effectiveRunTime} from which this sync can run. */
|
||||||
public long flexTime;
|
public long flexTime;
|
||||||
|
|
||||||
public SyncOperation(Account account, int userId, int reason, int source, String authority,
|
public SyncOperation(Account account, int userId, int reason, int source, String authority,
|
||||||
@@ -98,11 +99,16 @@ public class SyncOperation implements Comparable {
|
|||||||
this.backoff = backoff;
|
this.backoff = backoff;
|
||||||
final long now = SystemClock.elapsedRealtime();
|
final long now = SystemClock.elapsedRealtime();
|
||||||
// Checks the extras bundle. Must occur after we set the internal bundle.
|
// Checks the extras bundle. Must occur after we set the internal bundle.
|
||||||
if (runTimeFromNow < 0 || isExpedited()) {
|
if (runTimeFromNow < 0) {
|
||||||
|
// Sanity check: Will always be true.
|
||||||
|
if (!this.extras.getBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, false)) {
|
||||||
|
this.extras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
|
||||||
|
}
|
||||||
this.expedited = true;
|
this.expedited = true;
|
||||||
this.latestRunTime = now;
|
this.latestRunTime = now;
|
||||||
this.flexTime = 0;
|
this.flexTime = 0;
|
||||||
} else {
|
} else {
|
||||||
|
this.extras.remove(ContentResolver.SYNC_EXTRAS_EXPEDITED);
|
||||||
this.expedited = false;
|
this.expedited = false;
|
||||||
this.latestRunTime = now + runTimeFromNow;
|
this.latestRunTime = now + runTimeFromNow;
|
||||||
this.flexTime = flexTime;
|
this.flexTime = flexTime;
|
||||||
@@ -111,6 +117,24 @@ public class SyncOperation implements Comparable {
|
|||||||
this.key = toKey();
|
this.key = toKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Only used to immediately reschedule a sync. */
|
||||||
|
SyncOperation(SyncOperation other) {
|
||||||
|
this.service = other.service;
|
||||||
|
this.account = other.account;
|
||||||
|
this.authority = other.authority;
|
||||||
|
this.userId = other.userId;
|
||||||
|
this.reason = other.reason;
|
||||||
|
this.syncSource = other.syncSource;
|
||||||
|
this.extras = new Bundle(other.extras);
|
||||||
|
this.expedited = other.expedited;
|
||||||
|
this.latestRunTime = SystemClock.elapsedRealtime();
|
||||||
|
this.flexTime = 0L;
|
||||||
|
this.backoff = other.backoff;
|
||||||
|
this.allowParallelSyncs = other.allowParallelSyncs;
|
||||||
|
this.updateEffectiveRunTime();
|
||||||
|
this.key = toKey();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure the bundle attached to this SyncOperation doesn't have unnecessary
|
* Make sure the bundle attached to this SyncOperation doesn't have unnecessary
|
||||||
* flags set.
|
* flags set.
|
||||||
@@ -138,24 +162,6 @@ public class SyncOperation implements Comparable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Only used to immediately reschedule a sync. */
|
|
||||||
SyncOperation(SyncOperation other) {
|
|
||||||
this.service = other.service;
|
|
||||||
this.account = other.account;
|
|
||||||
this.authority = other.authority;
|
|
||||||
this.userId = other.userId;
|
|
||||||
this.reason = other.reason;
|
|
||||||
this.syncSource = other.syncSource;
|
|
||||||
this.extras = new Bundle(other.extras);
|
|
||||||
this.expedited = other.expedited;
|
|
||||||
this.latestRunTime = SystemClock.elapsedRealtime();
|
|
||||||
this.flexTime = 0L;
|
|
||||||
this.backoff = other.backoff;
|
|
||||||
this.allowParallelSyncs = other.allowParallelSyncs;
|
|
||||||
this.updateEffectiveRunTime();
|
|
||||||
this.key = toKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return dump(null, true);
|
return dump(null, true);
|
||||||
@@ -220,7 +226,7 @@ public class SyncOperation implements Comparable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExpedited() {
|
public boolean isExpedited() {
|
||||||
return extras.getBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, false) || expedited;
|
return expedited;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean ignoreBackoff() {
|
public boolean ignoreBackoff() {
|
||||||
|
|||||||
@@ -73,10 +73,9 @@ public class SyncQueue {
|
|||||||
}
|
}
|
||||||
SyncOperation syncOperation = new SyncOperation(
|
SyncOperation syncOperation = new SyncOperation(
|
||||||
op.account, op.userId, op.reason, op.syncSource, op.authority, op.extras,
|
op.account, op.userId, op.reason, op.syncSource, op.authority, op.extras,
|
||||||
0 /* delay */, 0 /* flex */, backoff != null ? backoff.first : 0,
|
op.expedited ? -1: 0 /* delay */, 0 /* flex */, backoff != null ? backoff.first : 0,
|
||||||
mSyncStorageEngine.getDelayUntilTime(op.account, op.userId, op.authority),
|
mSyncStorageEngine.getDelayUntilTime(op.account, op.userId, op.authority),
|
||||||
syncAdapterInfo.type.allowParallelSyncs());
|
syncAdapterInfo.type.allowParallelSyncs());
|
||||||
syncOperation.expedited = op.expedited;
|
|
||||||
syncOperation.pendingOperation = op;
|
syncOperation.pendingOperation = op;
|
||||||
add(syncOperation, op);
|
add(syncOperation, op);
|
||||||
}
|
}
|
||||||
@@ -104,7 +103,6 @@ public class SyncQueue {
|
|||||||
if (existingOperation != null) {
|
if (existingOperation != null) {
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
if (operation.compareTo(existingOperation) <= 0 ) {
|
if (operation.compareTo(existingOperation) <= 0 ) {
|
||||||
existingOperation.expedited = operation.expedited;
|
|
||||||
long newRunTime =
|
long newRunTime =
|
||||||
Math.min(existingOperation.latestRunTime, operation.latestRunTime);
|
Math.min(existingOperation.latestRunTime, operation.latestRunTime);
|
||||||
// Take smaller runtime.
|
// Take smaller runtime.
|
||||||
@@ -123,7 +121,7 @@ public class SyncQueue {
|
|||||||
if (operation.pendingOperation == null) {
|
if (operation.pendingOperation == null) {
|
||||||
pop = new SyncStorageEngine.PendingOperation(
|
pop = new SyncStorageEngine.PendingOperation(
|
||||||
operation.account, operation.userId, operation.reason, operation.syncSource,
|
operation.account, operation.userId, operation.reason, operation.syncSource,
|
||||||
operation.authority, operation.extras, operation.expedited);
|
operation.authority, operation.extras, operation.isExpedited());
|
||||||
pop = mSyncStorageEngine.insertIntoPending(pop);
|
pop = mSyncStorageEngine.insertIntoPending(pop);
|
||||||
if (pop == null) {
|
if (pop == null) {
|
||||||
throw new IllegalStateException("error adding pending sync operation "
|
throw new IllegalStateException("error adding pending sync operation "
|
||||||
|
|||||||
@@ -501,7 +501,7 @@ public class SyncStorageEngine extends Handler {
|
|||||||
* @return amount of seconds before syncTimeSeconds that the sync can occur.
|
* @return amount of seconds before syncTimeSeconds that the sync can occur.
|
||||||
* I.e.
|
* I.e.
|
||||||
* earliest_sync_time = syncTimeSeconds - calculateDefaultFlexTime(syncTimeSeconds)
|
* earliest_sync_time = syncTimeSeconds - calculateDefaultFlexTime(syncTimeSeconds)
|
||||||
* The flex time is capped at a percentage of the {@link DEFAULT_POLL_FREQUENCY_SECONDS}.
|
* The flex time is capped at a percentage of the {@link #DEFAULT_POLL_FREQUENCY_SECONDS}.
|
||||||
*/
|
*/
|
||||||
public static long calculateDefaultFlexTime(long syncTimeSeconds) {
|
public static long calculateDefaultFlexTime(long syncTimeSeconds) {
|
||||||
if (syncTimeSeconds < DEFAULT_MIN_FLEX_ALLOWED_SECS) {
|
if (syncTimeSeconds < DEFAULT_MIN_FLEX_ALLOWED_SECS) {
|
||||||
|
|||||||
@@ -136,10 +136,11 @@ public class SyncOperationTest extends AndroidTestCase {
|
|||||||
"authority1", b1, soon + 100, soonFlex + 100, unimportant, unimportant, true);
|
"authority1", b1, soon + 100, soonFlex + 100, unimportant, unimportant, true);
|
||||||
|
|
||||||
assertTrue(op1.compareTo(op2) == -1);
|
assertTrue(op1.compareTo(op2) == -1);
|
||||||
assertTrue("less than not transitive.", op2.compareTo(op1) == 1);
|
assertTrue("Less than not transitive.", op2.compareTo(op1) == 1);
|
||||||
assertTrue(op1.compareTo(op3) == 1);
|
assertEquals("Expedited not smaller than non-expedited.", -1, op1.compareTo(op3));
|
||||||
assertTrue("greater than not transitive. ", op3.compareTo(op1) == -1);
|
assertEquals("Greater than not transitive for expedited. ", 1, op3.compareTo(op1));
|
||||||
assertTrue("overlapping intervals not the same.", op1.compareTo(op4) == 0);
|
assertTrue("overlapping intervals not compared based on start interval.",
|
||||||
assertTrue("equality not transitive.", op4.compareTo(op1) == 0);
|
op1.compareTo(op4) == -1);
|
||||||
|
assertTrue("overlapping interval comparison not transitive.", op4.compareTo(op1) == 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user