Skip to content

Commit

Permalink
WorkManager: add stop reason to debug info and sync logs (bitfireAT/d…
Browse files Browse the repository at this point in the history
  • Loading branch information
rfc2822 committed Oct 23, 2023
1 parent fe679da commit 8263b5f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 32 deletions.
10 changes: 5 additions & 5 deletions app/src/main/kotlin/at/bitfire/davdroid/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class App: Application(), Thread.UncaughtExceptionHandler, Configuration.Provide

@Inject lateinit var workerFactory: HiltWorkerFactory

override val workManagerConfiguration: Configuration
get() = Configuration.Builder()
.setWorkerFactory(workerFactory)
.build()

override fun onCreate() {
super.onCreate()
Logger.initialize(this)
Expand Down Expand Up @@ -108,11 +113,6 @@ class App: Application(), Thread.UncaughtExceptionHandler, Configuration.Provide
}
}

override fun getWorkManagerConfiguration() =
Configuration.Builder()
.setWorkerFactory(workerFactory)
.build()

override fun uncaughtException(t: Thread, e: Throwable) {
Logger.log.log(Level.SEVERE, "Unhandled exception!", e)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.accounts.Account
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import androidx.concurrent.futures.CallbackToFutureAdapter
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
Expand Down Expand Up @@ -238,7 +239,7 @@ class RefreshCollectionsWorker @AssistedInject constructor(
}

override fun onStopped() {
Logger.log.info("Stopping refresh")
Logger.log.info("Stopping refresh (reason ${if (Build.VERSION.SDK_INT >= 31) stopReason else "n/a"})")
refreshThread?.interrupt()
}

Expand Down
23 changes: 3 additions & 20 deletions app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
package at.bitfire.davdroid.syncadapter

import android.accounts.Account
import android.content.ContentProviderClient
import android.content.ContentResolver
import android.content.Context
import android.content.Intent
import android.content.SyncResult
import android.content.*
import android.net.ConnectivityManager
import android.net.wifi.WifiManager
import android.os.Build
Expand All @@ -23,20 +19,7 @@ import androidx.core.content.getSystemService
import androidx.hilt.work.HiltWorker
import androidx.lifecycle.LiveData
import androidx.lifecycle.map
import androidx.work.BackoffPolicy
import androidx.work.Constraints
import androidx.work.Data
import androidx.work.ExistingWorkPolicy
import androidx.work.ForegroundInfo
import androidx.work.NetworkType
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.OutOfQuotaPolicy
import androidx.work.WorkInfo
import androidx.work.WorkManager
import androidx.work.WorkQuery
import androidx.work.WorkRequest
import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.*
import at.bitfire.davdroid.R
import at.bitfire.davdroid.log.Logger
import at.bitfire.davdroid.network.ConnectionUtils.internetAvailable
Expand Down Expand Up @@ -432,7 +415,7 @@ class SyncWorker @AssistedInject constructor(
}

override fun onStopped() {
Logger.log.info("Stopping sync thread")
Logger.log.info("Work stopped (reason ${if (Build.VERSION.SDK_INT >= 31) stopReason else "n/a"}), stopping sync thread")
syncThread?.interrupt()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import org.apache.commons.lang3.StringUtils
import org.apache.commons.lang3.exception.ExceptionUtils
import org.dmfs.tasks.contract.TaskContract
import java.io.*
import java.util.Locale
import java.util.TimeZone
import java.util.logging.Level
import java.util.zip.ZipEntry
Expand Down Expand Up @@ -680,7 +679,7 @@ class DebugInfoActivity : AppCompatActivity() {
table.addLine(
workInfo.tags.map { StringUtils.removeStartIgnoreCase(it, SyncWorker::class.java.getPackage()!!.name + ".") },
authority,
workInfo.state,
"${workInfo.state} (${workInfo.stopReason})",
workInfo.runAttemptCount,
workInfo.generation,
workInfo.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.launch
import kotlinx.coroutines.*
import java.util.logging.Level
import javax.inject.Inject

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
// * com.google.devtools.ksp at the end of this file
okhttp: '4.11.0',
room: '2.5.2',
workManager: '2.8.1',
workManager: '2.9.0-rc01',
// Apache Commons versions
commonsCollections: '4.4',
commonsLang: '3.13.0',
Expand Down

0 comments on commit 8263b5f

Please sign in to comment.