@@ -37,9 +37,6 @@ import at.bitfire.davdroid.repository.DavServiceRepository
37
37
import at.bitfire.davdroid.repository.DavSyncStatsRepository
38
38
import at.bitfire.davdroid.resource.LocalCollection
39
39
import at.bitfire.davdroid.resource.LocalResource
40
- import at.bitfire.davdroid.sync.SyncManager.Companion.DELAY_UNTIL_DEFAULT
41
- import at.bitfire.davdroid.sync.SyncManager.Companion.DELAY_UNTIL_MAX
42
- import at.bitfire.davdroid.sync.SyncManager.Companion.DELAY_UNTIL_MIN
43
40
import at.bitfire.davdroid.sync.account.InvalidAccountException
44
41
import at.bitfire.ical4android.CalendarStorageException
45
42
import at.bitfire.vcard4android.ContactsStorageException
@@ -53,7 +50,6 @@ import java.io.IOException
53
50
import java.io.InterruptedIOException
54
51
import java.net.HttpURLConnection
55
52
import java.security.cert.CertificateException
56
- import java.time.Instant
57
53
import java.util.LinkedList
58
54
import java.util.concurrent.LinkedBlockingQueue
59
55
import java.util.logging.Level
@@ -96,58 +92,28 @@ abstract class SyncManager<ResourceType: LocalResource<*>, out CollectionType: L
96
92
/* * Maximum number of resources that are requested with one multiget request. */
97
93
const val MAX_MULTIGET_RESOURCES = 10
98
94
99
- const val DELAY_UNTIL_DEFAULT = 15 * 60L // 15 min
100
- const val DELAY_UNTIL_MIN = 1 * 60L // 1 min
101
- const val DELAY_UNTIL_MAX = 2 * 60 * 60L // 2 hours
102
-
103
- /* *
104
- * Returns appropriate sync retry delay in seconds, considering the servers suggestion
105
- * ([DELAY_UNTIL_DEFAULT] if no server suggestion).
106
- *
107
- * Takes current time into account to calculate intervals. Interval
108
- * will be restricted to values between [DELAY_UNTIL_MIN] and [DELAY_UNTIL_MAX].
109
- *
110
- * @param retryAfter optional server suggestion on how long to wait before retrying
111
- * @return until when to wait before sync can be retried
112
- */
113
- fun getDelayUntil (retryAfter : Instant ? ): Instant {
114
- val now = Instant .now()
115
-
116
- if (retryAfter == null )
117
- return now.plusSeconds(DELAY_UNTIL_DEFAULT )
118
-
119
- // take server suggestion, but restricted to plausible min/max values
120
- val min = now.plusSeconds(DELAY_UNTIL_MIN )
121
- val max = now.plusSeconds(DELAY_UNTIL_MAX )
122
- return when {
123
- min > retryAfter -> min
124
- max < retryAfter -> max
125
- else -> retryAfter
126
- }
127
- }
128
-
129
95
}
130
96
131
97
98
+ @Inject
99
+ lateinit var accountRepository: AccountRepository
100
+
101
+ @Inject
102
+ lateinit var collectionRepository: DavCollectionRepository
103
+
132
104
@Inject
133
105
@ApplicationContext
134
106
lateinit var context: Context
135
107
136
108
@Inject
137
109
lateinit var logger: Logger
138
110
139
- @Inject
140
- lateinit var accountRepository: AccountRepository
141
-
142
111
@Inject
143
112
lateinit var syncStatsRepository: DavSyncStatsRepository
144
113
145
114
@Inject
146
115
lateinit var serviceRepository: DavServiceRepository
147
116
148
- @Inject
149
- lateinit var collectionRepository: DavCollectionRepository
150
-
151
117
@Inject
152
118
lateinit var syncNotificationManagerFactory: SyncNotificationManager .Factory
153
119
@@ -318,7 +284,7 @@ abstract class SyncManager<ResourceType: LocalResource<*>, out CollectionType: L
318
284
is ServiceUnavailableException -> {
319
285
logger.log(Level .WARNING , " Got 503 Service unavailable, trying again later" , e)
320
286
// determine when to retry
321
- syncResult.delayUntil = getDelayUntil(e.retryAfter ).epochSecond
287
+ syncResult.delayUntil = e.getDelayUntil( ).epochSecond
322
288
syncResult.numServiceUnavailableExceptions++ // Indicate a soft error occurred
323
289
}
324
290
0 commit comments