mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Rename parameters for clarity
This commit is contained in:
parent
b20bbc1295
commit
e771b21ea3
@ -40,7 +40,14 @@ class AlarmSyncBroadcastReceiver : BroadcastReceiver() {
|
||||
?: return Unit.also { Timber.v("No active session, so don't launch sync service.") }
|
||||
|
||||
val sessionId = intent.getStringExtra(SyncService.EXTRA_SESSION_ID) ?: return
|
||||
VectorSyncService.newPeriodicIntent(context, sessionId, vectorPreferences.backgroundSyncTimeOut(), vectorPreferences.backgroundSyncDelay()).let {
|
||||
VectorSyncService.newPeriodicIntent(
|
||||
context = context,
|
||||
sessionId = sessionId,
|
||||
syncTimeoutSeconds = vectorPreferences.backgroundSyncTimeOut(),
|
||||
syncDelaySeconds = vectorPreferences.backgroundSyncDelay(),
|
||||
isNetworkBack = false
|
||||
)
|
||||
.let {
|
||||
try {
|
||||
ContextCompat.startForegroundService(context, it)
|
||||
} catch (ex: Throwable) {
|
||||
|
@ -38,7 +38,12 @@ fun Session.startSyncing(context: Context) {
|
||||
val applicationContext = context.applicationContext
|
||||
if (!hasAlreadySynced()) {
|
||||
// initial sync is done as a service so it can continue below app lifecycle
|
||||
VectorSyncService.newOneShotIntent(applicationContext, sessionId, 0).also {
|
||||
VectorSyncService.newOneShotIntent(
|
||||
context = applicationContext,
|
||||
sessionId = sessionId,
|
||||
syncTimeoutSeconds = 0
|
||||
)
|
||||
.let {
|
||||
try {
|
||||
ContextCompat.startForegroundService(applicationContext, it)
|
||||
} catch (ex: Throwable) {
|
||||
|
@ -41,27 +41,27 @@ class VectorSyncService : SyncService() {
|
||||
|
||||
companion object {
|
||||
|
||||
fun newOneShotIntent(context: Context, sessionId: String, timeoutSeconds: Int): Intent {
|
||||
fun newOneShotIntent(context: Context,
|
||||
sessionId: String,
|
||||
syncTimeoutSeconds: Int): Intent {
|
||||
return Intent(context, VectorSyncService::class.java).also {
|
||||
it.putExtra(EXTRA_SESSION_ID, sessionId)
|
||||
it.putExtra(EXTRA_TIMEOUT_SECONDS, timeoutSeconds)
|
||||
it.putExtra(EXTRA_TIMEOUT_SECONDS, syncTimeoutSeconds)
|
||||
it.putExtra(EXTRA_PERIODIC, false)
|
||||
}
|
||||
}
|
||||
|
||||
fun newPeriodicIntent(
|
||||
context: Context,
|
||||
fun newPeriodicIntent(context: Context,
|
||||
sessionId: String,
|
||||
timeoutSeconds: Int,
|
||||
delayInSeconds: Int,
|
||||
networkBack: Boolean = false
|
||||
): Intent {
|
||||
syncTimeoutSeconds: Int,
|
||||
syncDelaySeconds: Int,
|
||||
isNetworkBack: Boolean): Intent {
|
||||
return Intent(context, VectorSyncService::class.java).also {
|
||||
it.putExtra(EXTRA_SESSION_ID, sessionId)
|
||||
it.putExtra(EXTRA_TIMEOUT_SECONDS, timeoutSeconds)
|
||||
it.putExtra(EXTRA_TIMEOUT_SECONDS, syncTimeoutSeconds)
|
||||
it.putExtra(EXTRA_PERIODIC, true)
|
||||
it.putExtra(EXTRA_DELAY_SECONDS, delayInSeconds)
|
||||
it.putExtra(EXTRA_NETWORK_BACK_RESTART, networkBack)
|
||||
it.putExtra(EXTRA_DELAY_SECONDS, syncDelaySeconds)
|
||||
it.putExtra(EXTRA_NETWORK_BACK_RESTART, isNetworkBack)
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,13 +154,19 @@ class VectorSyncService : SyncService() {
|
||||
}
|
||||
|
||||
private fun Context.rescheduleSyncService(sessionId: String,
|
||||
timeout: Int,
|
||||
delay: Int,
|
||||
syncTimeoutSeconds: Int,
|
||||
syncDelaySeconds: Int,
|
||||
isNetworkBack: Boolean) {
|
||||
Timber.d("## Sync: rescheduleSyncService")
|
||||
val periodicIntent = VectorSyncService.newPeriodicIntent(this, sessionId, timeout, delay, isNetworkBack)
|
||||
val periodicIntent = VectorSyncService.newPeriodicIntent(
|
||||
context = this,
|
||||
sessionId = sessionId,
|
||||
syncTimeoutSeconds = syncTimeoutSeconds,
|
||||
syncDelaySeconds = syncDelaySeconds,
|
||||
isNetworkBack = isNetworkBack
|
||||
)
|
||||
|
||||
if (isNetworkBack || delay == 0) {
|
||||
if (isNetworkBack || syncDelaySeconds == 0) {
|
||||
// Do not wait, do the sync now (more reactivity if network back is due to user action)
|
||||
startService(periodicIntent)
|
||||
} else {
|
||||
@ -169,7 +175,7 @@ private fun Context.rescheduleSyncService(sessionId: String,
|
||||
} else {
|
||||
PendingIntent.getService(this, 0, periodicIntent, 0)
|
||||
}
|
||||
val firstMillis = System.currentTimeMillis() + delay * 1000L
|
||||
val firstMillis = System.currentTimeMillis() + syncDelaySeconds * 1000L
|
||||
val alarmMgr = getSystemService<AlarmManager>()!!
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
alarmMgr.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, firstMillis, pendingIntent)
|
||||
|
Loading…
Reference in New Issue
Block a user