* commit 'd5fe5a8fa1f770b929dbd786381a6ad45a754301': Remove spurious syncmanager wake-ups
This commit is contained in:
@@ -1781,14 +1781,6 @@ public class Intent implements Parcelable, Cloneable {
|
|||||||
*/
|
*/
|
||||||
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
|
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
|
||||||
public static final String ACTION_ALARM_CHANGED = "android.intent.action.ALARM_CHANGED";
|
public static final String ACTION_ALARM_CHANGED = "android.intent.action.ALARM_CHANGED";
|
||||||
/**
|
|
||||||
* Sync State Changed Action: This is broadcast when the sync starts or stops or when one has
|
|
||||||
* been failing for a long time. It is used by the SyncManager and the StatusBar service.
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
|
|
||||||
public static final String ACTION_SYNC_STATE_CHANGED
|
|
||||||
= "android.intent.action.SYNC_STATE_CHANGED";
|
|
||||||
/**
|
/**
|
||||||
* Broadcast Action: This is broadcast once, after the system has finished
|
* Broadcast Action: This is broadcast once, after the system has finished
|
||||||
* booting. It can be used to perform application-specific initialization,
|
* booting. It can be used to perform application-specific initialization,
|
||||||
|
|||||||
@@ -297,7 +297,6 @@ public class SyncManager {
|
|||||||
private final UserManager mUserManager;
|
private final UserManager mUserManager;
|
||||||
|
|
||||||
private static final long SYNC_ALARM_TIMEOUT_MIN = 30 * 1000; // 30 seconds
|
private static final long SYNC_ALARM_TIMEOUT_MIN = 30 * 1000; // 30 seconds
|
||||||
private static final long SYNC_ALARM_TIMEOUT_MAX = 2 * 60 * 60 * 1000; // two hours
|
|
||||||
|
|
||||||
private List<UserInfo> getAllUsers() {
|
private List<UserInfo> getAllUsers() {
|
||||||
return mUserManager.getUsers();
|
return mUserManager.getUsers();
|
||||||
@@ -1478,9 +1477,9 @@ public class SyncManager {
|
|||||||
final long now = SystemClock.elapsedRealtime();
|
final long now = SystemClock.elapsedRealtime();
|
||||||
pw.print("now: "); pw.print(now);
|
pw.print("now: "); pw.print(now);
|
||||||
pw.println(" (" + formatTime(System.currentTimeMillis()) + ")");
|
pw.println(" (" + formatTime(System.currentTimeMillis()) + ")");
|
||||||
pw.print("offset: "); pw.print(DateUtils.formatElapsedTime(mSyncRandomOffsetMillis/1000));
|
pw.print("offset: "); pw.print(DateUtils.formatElapsedTime(mSyncRandomOffsetMillis / 1000));
|
||||||
pw.println(" (HH:MM:SS)");
|
pw.println(" (HH:MM:SS)");
|
||||||
pw.print("uptime: "); pw.print(DateUtils.formatElapsedTime(now/1000));
|
pw.print("uptime: "); pw.print(DateUtils.formatElapsedTime(now / 1000));
|
||||||
pw.println(" (HH:MM:SS)");
|
pw.println(" (HH:MM:SS)");
|
||||||
pw.print("time spent syncing: ");
|
pw.print("time spent syncing: ");
|
||||||
pw.print(DateUtils.formatElapsedTime(
|
pw.print(DateUtils.formatElapsedTime(
|
||||||
@@ -1497,11 +1496,6 @@ public class SyncManager {
|
|||||||
pw.println("no alarm is scheduled (there had better not be any pending syncs)");
|
pw.println("no alarm is scheduled (there had better not be any pending syncs)");
|
||||||
}
|
}
|
||||||
|
|
||||||
pw.print("notification info: ");
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
|
||||||
mSyncHandler.mSyncNotificationInfo.toString(sb);
|
|
||||||
pw.println(sb.toString());
|
|
||||||
|
|
||||||
pw.println();
|
pw.println();
|
||||||
pw.println("Active Syncs: " + mActiveSyncContexts.size());
|
pw.println("Active Syncs: " + mActiveSyncContexts.size());
|
||||||
final PackageManager pm = mContext.getPackageManager();
|
final PackageManager pm = mContext.getPackageManager();
|
||||||
@@ -1514,8 +1508,8 @@ public class SyncManager {
|
|||||||
pw.println();
|
pw.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final StringBuilder sb = new StringBuilder();
|
||||||
synchronized (mSyncQueue) {
|
synchronized (mSyncQueue) {
|
||||||
sb.setLength(0);
|
|
||||||
mSyncQueue.dump(sb);
|
mSyncQueue.dump(sb);
|
||||||
// Dump Pending Operations.
|
// Dump Pending Operations.
|
||||||
getSyncStorageEngine().dumpPendingOperations(sb);
|
getSyncStorageEngine().dumpPendingOperations(sb);
|
||||||
@@ -2349,7 +2343,6 @@ public class SyncManager {
|
|||||||
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
manageSyncNotificationLocked();
|
|
||||||
manageSyncAlarmLocked(earliestFuturePollTime, nextPendingSyncTime);
|
manageSyncAlarmLocked(earliestFuturePollTime, nextPendingSyncTime);
|
||||||
mSyncTimeTracker.update();
|
mSyncTimeTracker.update();
|
||||||
mSyncManagerWakeLock.release();
|
mSyncManagerWakeLock.release();
|
||||||
@@ -3169,67 +3162,6 @@ public class SyncManager {
|
|||||||
throw new IllegalStateException("we are not in an error state, " + syncResult);
|
throw new IllegalStateException("we are not in an error state, " + syncResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void manageSyncNotificationLocked() {
|
|
||||||
boolean shouldCancel;
|
|
||||||
boolean shouldInstall;
|
|
||||||
|
|
||||||
if (mActiveSyncContexts.isEmpty()) {
|
|
||||||
mSyncNotificationInfo.startTime = null;
|
|
||||||
|
|
||||||
// we aren't syncing. if the notification is active then remember that we need
|
|
||||||
// to cancel it and then clear out the info
|
|
||||||
shouldCancel = mSyncNotificationInfo.isActive;
|
|
||||||
shouldInstall = false;
|
|
||||||
} else {
|
|
||||||
// we are syncing
|
|
||||||
final long now = SystemClock.elapsedRealtime();
|
|
||||||
if (mSyncNotificationInfo.startTime == null) {
|
|
||||||
mSyncNotificationInfo.startTime = now;
|
|
||||||
}
|
|
||||||
|
|
||||||
// there are three cases:
|
|
||||||
// - the notification is up: do nothing
|
|
||||||
// - the notification is not up but it isn't time yet: don't install
|
|
||||||
// - the notification is not up and it is time: need to install
|
|
||||||
|
|
||||||
if (mSyncNotificationInfo.isActive) {
|
|
||||||
shouldInstall = shouldCancel = false;
|
|
||||||
} else {
|
|
||||||
// it isn't currently up, so there is nothing to cancel
|
|
||||||
shouldCancel = false;
|
|
||||||
|
|
||||||
final boolean timeToShowNotification =
|
|
||||||
now > mSyncNotificationInfo.startTime + SYNC_NOTIFICATION_DELAY;
|
|
||||||
if (timeToShowNotification) {
|
|
||||||
shouldInstall = true;
|
|
||||||
} else {
|
|
||||||
// show the notification immediately if this is a manual sync
|
|
||||||
shouldInstall = false;
|
|
||||||
for (ActiveSyncContext activeSyncContext : mActiveSyncContexts) {
|
|
||||||
final boolean manualSync = activeSyncContext.mSyncOperation.extras
|
|
||||||
.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
|
|
||||||
if (manualSync) {
|
|
||||||
shouldInstall = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldCancel && !shouldInstall) {
|
|
||||||
mNeedSyncActiveNotification = false;
|
|
||||||
sendSyncStateIntent();
|
|
||||||
mSyncNotificationInfo.isActive = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldInstall) {
|
|
||||||
mNeedSyncActiveNotification = true;
|
|
||||||
sendSyncStateIntent();
|
|
||||||
mSyncNotificationInfo.isActive = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void manageSyncAlarmLocked(long nextPeriodicEventElapsedTime,
|
private void manageSyncAlarmLocked(long nextPeriodicEventElapsedTime,
|
||||||
long nextPendingEventElapsedTime) {
|
long nextPendingEventElapsedTime) {
|
||||||
// in each of these cases the sync loop will be kicked, which will cause this
|
// in each of these cases the sync loop will be kicked, which will cause this
|
||||||
@@ -3238,13 +3170,6 @@ public class SyncManager {
|
|||||||
if (mStorageIsLow) return;
|
if (mStorageIsLow) return;
|
||||||
if (mDeviceIsIdle) return;
|
if (mDeviceIsIdle) return;
|
||||||
|
|
||||||
// When the status bar notification should be raised
|
|
||||||
final long notificationTime =
|
|
||||||
(!mSyncHandler.mSyncNotificationInfo.isActive
|
|
||||||
&& mSyncHandler.mSyncNotificationInfo.startTime != null)
|
|
||||||
? mSyncHandler.mSyncNotificationInfo.startTime + SYNC_NOTIFICATION_DELAY
|
|
||||||
: Long.MAX_VALUE;
|
|
||||||
|
|
||||||
// When we should consider canceling an active sync
|
// When we should consider canceling an active sync
|
||||||
long earliestTimeoutTime = Long.MAX_VALUE;
|
long earliestTimeoutTime = Long.MAX_VALUE;
|
||||||
for (ActiveSyncContext currentSyncContext : mActiveSyncContexts) {
|
for (ActiveSyncContext currentSyncContext : mActiveSyncContexts) {
|
||||||
@@ -3259,25 +3184,15 @@ public class SyncManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
|
||||||
Log.v(TAG, "manageSyncAlarm: notificationTime is " + notificationTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
||||||
Log.v(TAG, "manageSyncAlarm: earliestTimeoutTime is " + earliestTimeoutTime);
|
Log.v(TAG, "manageSyncAlarm: earliestTimeoutTime is " + earliestTimeoutTime);
|
||||||
}
|
|
||||||
|
|
||||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
|
||||||
Log.v(TAG, "manageSyncAlarm: nextPeriodicEventElapsedTime is "
|
Log.v(TAG, "manageSyncAlarm: nextPeriodicEventElapsedTime is "
|
||||||
+ nextPeriodicEventElapsedTime);
|
+ nextPeriodicEventElapsedTime);
|
||||||
}
|
|
||||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
|
||||||
Log.v(TAG, "manageSyncAlarm: nextPendingEventElapsedTime is "
|
Log.v(TAG, "manageSyncAlarm: nextPendingEventElapsedTime is "
|
||||||
+ nextPendingEventElapsedTime);
|
+ nextPendingEventElapsedTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
long alarmTime = Math.min(notificationTime, earliestTimeoutTime);
|
long alarmTime = Math.min(earliestTimeoutTime, nextPeriodicEventElapsedTime);
|
||||||
alarmTime = Math.min(alarmTime, nextPeriodicEventElapsedTime);
|
|
||||||
alarmTime = Math.min(alarmTime, nextPendingEventElapsedTime);
|
alarmTime = Math.min(alarmTime, nextPendingEventElapsedTime);
|
||||||
|
|
||||||
// Bound the alarm time.
|
// Bound the alarm time.
|
||||||
@@ -3288,24 +3203,16 @@ public class SyncManager {
|
|||||||
+ alarmTime + ", setting to " + (now + SYNC_ALARM_TIMEOUT_MIN));
|
+ alarmTime + ", setting to " + (now + SYNC_ALARM_TIMEOUT_MIN));
|
||||||
}
|
}
|
||||||
alarmTime = now + SYNC_ALARM_TIMEOUT_MIN;
|
alarmTime = now + SYNC_ALARM_TIMEOUT_MIN;
|
||||||
} else if (alarmTime > now + SYNC_ALARM_TIMEOUT_MAX) {
|
|
||||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
|
||||||
Log.v(TAG, "manageSyncAlarm: the alarmTime is too large, "
|
|
||||||
+ alarmTime + ", setting to " + (now + SYNC_ALARM_TIMEOUT_MIN));
|
|
||||||
}
|
|
||||||
alarmTime = now + SYNC_ALARM_TIMEOUT_MAX;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine if we need to set or cancel the alarm
|
// Determine if we need to set or cancel the alarm
|
||||||
boolean shouldSet = false;
|
boolean shouldSet = false;
|
||||||
boolean shouldCancel = false;
|
boolean shouldCancel = false;
|
||||||
final boolean alarmIsActive = (mAlarmScheduleTime != null) && (now < mAlarmScheduleTime);
|
final boolean alarmIsActive = (mAlarmScheduleTime != null) && (now < mAlarmScheduleTime);
|
||||||
final boolean needAlarm = alarmTime != Long.MAX_VALUE;
|
|
||||||
if (needAlarm) {
|
if (alarmTime != Long.MAX_VALUE) {
|
||||||
// Need the alarm if
|
// Need the alarm if it isn't set or has changed.
|
||||||
// - it's currently not set
|
if (!alarmIsActive || alarmTime != mAlarmScheduleTime) {
|
||||||
// - if the alarm is set in the past.
|
|
||||||
if (!alarmIsActive || alarmTime < mAlarmScheduleTime) {
|
|
||||||
shouldSet = true;
|
shouldSet = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -3329,14 +3236,6 @@ public class SyncManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendSyncStateIntent() {
|
|
||||||
Intent syncStateIntent = new Intent(Intent.ACTION_SYNC_STATE_CHANGED);
|
|
||||||
syncStateIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
|
|
||||||
syncStateIntent.putExtra("active", mNeedSyncActiveNotification);
|
|
||||||
syncStateIntent.putExtra("failing", false);
|
|
||||||
mContext.sendBroadcastAsUser(syncStateIntent, UserHandle.OWNER);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void installHandleTooManyDeletesNotification(Account account, String authority,
|
private void installHandleTooManyDeletesNotification(Account account, String authority,
|
||||||
long numDeletes, int userId) {
|
long numDeletes, int userId) {
|
||||||
if (mNotificationMgr == null) return;
|
if (mNotificationMgr == null) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user