Skip to content

Commit 2e61ed3

Browse files
authored
Move AccountSettings access in CollectionScreenViewModel off main thread (#2217)
Annotate `getByDbCollectionId` with `@WorkerThread` and move local data store access off main thread
1 parent c3285ea commit 2e61ed3

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

core/src/main/kotlin/at/bitfire/davdroid/resource/LocalDataStore.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package at.bitfire.davdroid.resource
66

77
import android.accounts.Account
88
import android.content.ContentProviderClient
9+
import androidx.annotation.WorkerThread
910
import at.bitfire.davdroid.db.Collection
1011
import javax.annotation.WillNotClose
1112

@@ -66,6 +67,7 @@ interface LocalDataStore<T: LocalCollection<*>> {
6667
* @return The local collection with the specified DB collection ID, or `null` if not found.
6768
* @throws UnsupportedOperationException if the operation is not supported on this data store (jtx Board)
6869
*/
70+
@WorkerThread
6971
fun getByDbCollectionId(account: Account, client: ContentProviderClient, dbCollectionId: Long): T?
7072

7173
/**

core/src/main/kotlin/at/bitfire/davdroid/ui/account/CollectionScreenViewModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import kotlinx.coroutines.flow.combine
5050
import kotlinx.coroutines.flow.emptyFlow
5151
import kotlinx.coroutines.flow.filterNotNull
5252
import kotlinx.coroutines.flow.flatMapLatest
53+
import kotlinx.coroutines.flow.flowOn
5354
import kotlinx.coroutines.flow.map
5455
import kotlinx.coroutines.flow.stateIn
5556
import kotlinx.coroutines.launch
@@ -304,7 +305,7 @@ class CollectionScreenViewModel @AssistedInject constructor(
304305
awaitClose {
305306
context.contentResolver.unregisterContentObserver(observer)
306307
}
307-
}
308+
}.flowOn(ioDispatcher) // localDataStore access should not be done on main thread
308309

309310
private fun getProviderAppName(authority: String): String {
310311
val packageManager = context.packageManager

0 commit comments

Comments
 (0)