Skip to content

Commit

Permalink
android: use a coroutine for loadfiles (#551)
Browse files Browse the repository at this point in the history
contentResolver.query is attempting to perform a network query on the main thread. Move this to a coroutine to prevent blocking.

Fixes tailscale/corp#24293

Signed-off-by: kari-ts <kari@tailscale.com>
  • Loading branch information
kari-ts authored Oct 31, 2024
1 parent e89c259 commit ba306bf
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion android/src/main/java/com/tailscale/ipn/ShareActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ import androidx.activity.compose.setContent
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.lifecycle.lifecycleScope
import com.tailscale.ipn.ui.model.Ipn
import com.tailscale.ipn.ui.theme.AppTheme
import com.tailscale.ipn.ui.util.set
import com.tailscale.ipn.ui.util.universalFit
import com.tailscale.ipn.ui.view.TaildropView
import com.tailscale.ipn.util.TSLog
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlin.random.Random

// ShareActivity is the entry point for Taildrop share intents
Expand All @@ -47,7 +51,7 @@ class ShareActivity : ComponentActivity() {
super.onStart()
// Ensure our app instance is initialized
App.get()
loadFiles()
lifecycleScope.launch { withContext(Dispatchers.IO) { loadFiles() } }
}

override fun onNewIntent(intent: Intent) {
Expand Down

0 comments on commit ba306bf

Please sign in to comment.