Merge pull request #6502 from thundernest/NotificationActionService_background_thread
`NotificationActionService` fixes
This commit is contained in:
commit
27f3ac9e8e
1 changed files with 24 additions and 4 deletions
|
@ -11,22 +11,44 @@ import com.fsck.k9.controller.MessageReference
|
|||
import com.fsck.k9.controller.MessageReferenceHelper
|
||||
import com.fsck.k9.controller.MessagingController
|
||||
import com.fsck.k9.mail.Flag
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.koin.core.qualifier.named
|
||||
import timber.log.Timber
|
||||
|
||||
class NotificationActionService : Service() {
|
||||
private val preferences: Preferences by inject()
|
||||
private val messagingController: MessagingController by inject()
|
||||
private val coroutineScope: CoroutineScope by inject(named("AppCoroutineScope"))
|
||||
|
||||
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
|
||||
Timber.i("NotificationActionService started with startId = %d", startId)
|
||||
|
||||
val accountUuid = intent.getStringExtra(EXTRA_ACCOUNT_UUID) ?: error("Missing account UUID")
|
||||
startHandleCommand(intent, startId)
|
||||
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
|
||||
private fun startHandleCommand(intent: Intent, startId: Int) {
|
||||
coroutineScope.launch(Dispatchers.IO) {
|
||||
handleCommand(intent)
|
||||
stopSelf(startId)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleCommand(intent: Intent) {
|
||||
val accountUuid = intent.getStringExtra(EXTRA_ACCOUNT_UUID)
|
||||
if (accountUuid == null) {
|
||||
Timber.w("Missing account UUID.")
|
||||
return
|
||||
}
|
||||
|
||||
val account = preferences.getAccount(accountUuid)
|
||||
if (account == null) {
|
||||
Timber.w("Could not find account for notification action.")
|
||||
return START_NOT_STICKY
|
||||
return
|
||||
}
|
||||
|
||||
when (intent.action) {
|
||||
|
@ -38,8 +60,6 @@ class NotificationActionService : Service() {
|
|||
}
|
||||
|
||||
cancelNotifications(intent, account)
|
||||
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
|
||||
override fun onBind(intent: Intent): IBinder? {
|
||||
|
|
Loading…
Reference in a new issue