@@ -297,7 +297,6 @@ public void onReceive(Context context, Intent intent) {
297297 private final UserManager mUserManager ;
298298
299299 private static final long SYNC_ALARM_TIMEOUT_MIN = 30 * 1000 ; // 30 seconds
300- private static final long SYNC_ALARM_TIMEOUT_MAX = 2 * 60 * 60 * 1000 ; // two hours
301300
302301 private List <UserInfo > getAllUsers () {
303302 return mUserManager .getUsers ();
@@ -1478,9 +1477,9 @@ protected void dumpSyncState(PrintWriter pw) {
14781477 final long now = SystemClock .elapsedRealtime ();
14791478 pw .print ("now: " ); pw .print (now );
14801479 pw .println (" (" + formatTime (System .currentTimeMillis ()) + ")" );
1481- pw .print ("offset: " ); pw .print (DateUtils .formatElapsedTime (mSyncRandomOffsetMillis / 1000 ));
1480+ pw .print ("offset: " ); pw .print (DateUtils .formatElapsedTime (mSyncRandomOffsetMillis / 1000 ));
14821481 pw .println (" (HH:MM:SS)" );
1483- pw .print ("uptime: " ); pw .print (DateUtils .formatElapsedTime (now / 1000 ));
1482+ pw .print ("uptime: " ); pw .print (DateUtils .formatElapsedTime (now / 1000 ));
14841483 pw .println (" (HH:MM:SS)" );
14851484 pw .print ("time spent syncing: " );
14861485 pw .print (DateUtils .formatElapsedTime (
@@ -1497,11 +1496,6 @@ protected void dumpSyncState(PrintWriter pw) {
14971496 pw .println ("no alarm is scheduled (there had better not be any pending syncs)" );
14981497 }
14991498
1500- pw .print ("notification info: " );
1501- final StringBuilder sb = new StringBuilder ();
1502- mSyncHandler .mSyncNotificationInfo .toString (sb );
1503- pw .println (sb .toString ());
1504-
15051499 pw .println ();
15061500 pw .println ("Active Syncs: " + mActiveSyncContexts .size ());
15071501 final PackageManager pm = mContext .getPackageManager ();
@@ -1514,8 +1508,8 @@ protected void dumpSyncState(PrintWriter pw) {
15141508 pw .println ();
15151509 }
15161510
1511+ final StringBuilder sb = new StringBuilder ();
15171512 synchronized (mSyncQueue ) {
1518- sb .setLength (0 );
15191513 mSyncQueue .dump (sb );
15201514 // Dump Pending Operations.
15211515 getSyncStorageEngine ().dumpPendingOperations (sb );
@@ -2349,7 +2343,6 @@ public void handleMessage(Message msg) {
23492343
23502344 }
23512345 } finally {
2352- manageSyncNotificationLocked ();
23532346 manageSyncAlarmLocked (earliestFuturePollTime , nextPendingSyncTime );
23542347 mSyncTimeTracker .update ();
23552348 mSyncManagerWakeLock .release ();
@@ -3169,67 +3162,6 @@ private int syncResultToErrorNumber(SyncResult syncResult) {
31693162 throw new IllegalStateException ("we are not in an error state, " + syncResult );
31703163 }
31713164
3172- private void manageSyncNotificationLocked () {
3173- boolean shouldCancel ;
3174- boolean shouldInstall ;
3175-
3176- if (mActiveSyncContexts .isEmpty ()) {
3177- mSyncNotificationInfo .startTime = null ;
3178-
3179- // we aren't syncing. if the notification is active then remember that we need
3180- // to cancel it and then clear out the info
3181- shouldCancel = mSyncNotificationInfo .isActive ;
3182- shouldInstall = false ;
3183- } else {
3184- // we are syncing
3185- final long now = SystemClock .elapsedRealtime ();
3186- if (mSyncNotificationInfo .startTime == null ) {
3187- mSyncNotificationInfo .startTime = now ;
3188- }
3189-
3190- // there are three cases:
3191- // - the notification is up: do nothing
3192- // - the notification is not up but it isn't time yet: don't install
3193- // - the notification is not up and it is time: need to install
3194-
3195- if (mSyncNotificationInfo .isActive ) {
3196- shouldInstall = shouldCancel = false ;
3197- } else {
3198- // it isn't currently up, so there is nothing to cancel
3199- shouldCancel = false ;
3200-
3201- final boolean timeToShowNotification =
3202- now > mSyncNotificationInfo .startTime + SYNC_NOTIFICATION_DELAY ;
3203- if (timeToShowNotification ) {
3204- shouldInstall = true ;
3205- } else {
3206- // show the notification immediately if this is a manual sync
3207- shouldInstall = false ;
3208- for (ActiveSyncContext activeSyncContext : mActiveSyncContexts ) {
3209- final boolean manualSync = activeSyncContext .mSyncOperation .extras
3210- .getBoolean (ContentResolver .SYNC_EXTRAS_MANUAL , false );
3211- if (manualSync ) {
3212- shouldInstall = true ;
3213- break ;
3214- }
3215- }
3216- }
3217- }
3218- }
3219-
3220- if (shouldCancel && !shouldInstall ) {
3221- mNeedSyncActiveNotification = false ;
3222- sendSyncStateIntent ();
3223- mSyncNotificationInfo .isActive = false ;
3224- }
3225-
3226- if (shouldInstall ) {
3227- mNeedSyncActiveNotification = true ;
3228- sendSyncStateIntent ();
3229- mSyncNotificationInfo .isActive = true ;
3230- }
3231- }
3232-
32333165 private void manageSyncAlarmLocked (long nextPeriodicEventElapsedTime ,
32343166 long nextPendingEventElapsedTime ) {
32353167 // in each of these cases the sync loop will be kicked, which will cause this
@@ -3238,13 +3170,6 @@ private void manageSyncAlarmLocked(long nextPeriodicEventElapsedTime,
32383170 if (mStorageIsLow ) return ;
32393171 if (mDeviceIsIdle ) return ;
32403172
3241- // When the status bar notification should be raised
3242- final long notificationTime =
3243- (!mSyncHandler .mSyncNotificationInfo .isActive
3244- && mSyncHandler .mSyncNotificationInfo .startTime != null )
3245- ? mSyncHandler .mSyncNotificationInfo .startTime + SYNC_NOTIFICATION_DELAY
3246- : Long .MAX_VALUE ;
3247-
32483173 // When we should consider canceling an active sync
32493174 long earliestTimeoutTime = Long .MAX_VALUE ;
32503175 for (ActiveSyncContext currentSyncContext : mActiveSyncContexts ) {
@@ -3259,25 +3184,15 @@ private void manageSyncAlarmLocked(long nextPeriodicEventElapsedTime,
32593184 }
32603185 }
32613186
3262- if (Log .isLoggable (TAG , Log .VERBOSE )) {
3263- Log .v (TAG , "manageSyncAlarm: notificationTime is " + notificationTime );
3264- }
3265-
32663187 if (Log .isLoggable (TAG , Log .VERBOSE )) {
32673188 Log .v (TAG , "manageSyncAlarm: earliestTimeoutTime is " + earliestTimeoutTime );
3268- }
3269-
3270- if (Log .isLoggable (TAG , Log .VERBOSE )) {
32713189 Log .v (TAG , "manageSyncAlarm: nextPeriodicEventElapsedTime is "
32723190 + nextPeriodicEventElapsedTime );
3273- }
3274- if (Log .isLoggable (TAG , Log .VERBOSE )) {
32753191 Log .v (TAG , "manageSyncAlarm: nextPendingEventElapsedTime is "
32763192 + nextPendingEventElapsedTime );
32773193 }
32783194
3279- long alarmTime = Math .min (notificationTime , earliestTimeoutTime );
3280- alarmTime = Math .min (alarmTime , nextPeriodicEventElapsedTime );
3195+ long alarmTime = Math .min (earliestTimeoutTime , nextPeriodicEventElapsedTime );
32813196 alarmTime = Math .min (alarmTime , nextPendingEventElapsedTime );
32823197
32833198 // Bound the alarm time.
@@ -3288,24 +3203,16 @@ private void manageSyncAlarmLocked(long nextPeriodicEventElapsedTime,
32883203 + alarmTime + ", setting to " + (now + SYNC_ALARM_TIMEOUT_MIN ));
32893204 }
32903205 alarmTime = now + SYNC_ALARM_TIMEOUT_MIN ;
3291- } else if (alarmTime > now + SYNC_ALARM_TIMEOUT_MAX ) {
3292- if (Log .isLoggable (TAG , Log .VERBOSE )) {
3293- Log .v (TAG , "manageSyncAlarm: the alarmTime is too large, "
3294- + alarmTime + ", setting to " + (now + SYNC_ALARM_TIMEOUT_MIN ));
3295- }
3296- alarmTime = now + SYNC_ALARM_TIMEOUT_MAX ;
32973206 }
32983207
3299- // determine if we need to set or cancel the alarm
3208+ // Determine if we need to set or cancel the alarm
33003209 boolean shouldSet = false ;
33013210 boolean shouldCancel = false ;
33023211 final boolean alarmIsActive = (mAlarmScheduleTime != null ) && (now < mAlarmScheduleTime );
3303- final boolean needAlarm = alarmTime != Long .MAX_VALUE ;
3304- if (needAlarm ) {
3305- // Need the alarm if
3306- // - it's currently not set
3307- // - if the alarm is set in the past.
3308- if (!alarmIsActive || alarmTime < mAlarmScheduleTime ) {
3212+
3213+ if (alarmTime != Long .MAX_VALUE ) {
3214+ // Need the alarm if it isn't set or has changed.
3215+ if (!alarmIsActive || alarmTime != mAlarmScheduleTime ) {
33093216 shouldSet = true ;
33103217 }
33113218 } else {
@@ -3329,14 +3236,6 @@ private void manageSyncAlarmLocked(long nextPeriodicEventElapsedTime,
33293236 }
33303237 }
33313238
3332- private void sendSyncStateIntent () {
3333- Intent syncStateIntent = new Intent (Intent .ACTION_SYNC_STATE_CHANGED );
3334- syncStateIntent .addFlags (Intent .FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT );
3335- syncStateIntent .putExtra ("active" , mNeedSyncActiveNotification );
3336- syncStateIntent .putExtra ("failing" , false );
3337- mContext .sendBroadcastAsUser (syncStateIntent , UserHandle .OWNER );
3338- }
3339-
33403239 private void installHandleTooManyDeletesNotification (Account account , String authority ,
33413240 long numDeletes , int userId ) {
33423241 if (mNotificationMgr == null ) return ;
0 commit comments