aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2021-01-24 17:19:08 -0800
committerAllan Wang <me@allanwang.ca>2021-01-24 17:19:08 -0800
commitc2f7e2e0c611e79b62ca43c7d8712b367796f5b5 (patch)
treebfc7a31a72495ccbb3a2eb3df5e2973b1c9334c5 /app
parente0f289862bb76c36c01db9b092cafeb4cf8f6ebc (diff)
downloadfrost-c2f7e2e0c611e79b62ca43c7d8712b367796f5b5.tar.gz
frost-c2f7e2e0c611e79b62ca43c7d8712b367796f5b5.tar.bz2
frost-c2f7e2e0c611e79b62ca43c7d8712b367796f5b5.zip
Require main thread for cookiemanager calls
Diffstat (limited to 'app')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt19
1 files changed, 12 insertions, 7 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
index db40495b..65955bdc 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
@@ -29,14 +29,14 @@ import com.pitchedapps.frost.prefs.Prefs
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.cookies
import com.pitchedapps.frost.utils.launchLogin
-import kotlin.coroutines.resume
-import kotlin.coroutines.suspendCoroutine
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.withContext
import org.koin.dsl.module
+import kotlin.coroutines.resume
+import kotlin.coroutines.suspendCoroutine
/**
* Created by Allan Wang on 2017-05-30.
@@ -64,7 +64,10 @@ class FbCookie(private val prefs: Prefs, private val cookieDao: CookieDao) {
val messengerCookie: String?
get() = CookieManager.getInstance().getCookie(HTTPS_MESSENGER_COM)
- private suspend fun CookieManager.suspendSetWebCookie(domain: String, cookie: String?): Boolean {
+ private suspend fun CookieManager.suspendSetWebCookie(
+ domain: String,
+ cookie: String?
+ ): Boolean {
cookie ?: return true
return withContext(NonCancellable) {
// Save all cookies regardless of result, then check if all succeeded
@@ -100,9 +103,11 @@ class FbCookie(private val prefs: Prefs, private val cookieDao: CookieDao) {
suspend fun reset() {
prefs.userId = -1L
- with(CookieManager.getInstance()) {
- removeAllCookies()
- flush()
+ withContext(Dispatchers.Main + NonCancellable) {
+ with(CookieManager.getInstance()) {
+ removeAllCookies()
+ flush()
+ }
}
}
@@ -117,7 +122,7 @@ class FbCookie(private val prefs: Prefs, private val cookieDao: CookieDao) {
return
}
val currentId = prefs.userId
- withContext(Dispatchers.IO + NonCancellable) {
+ withContext(Dispatchers.Main + NonCancellable) {
L.d { "Switching User" }
// Save current messenger cookie state.
cookieDao.updateMessengerCookie(currentId, messengerCookie)