Skip to content

Commit 747c4af

Browse files
authored
Fix ANR in DuckPlayerLocalFilesPath (#5340)
Task/Issue URL: https://app.asana.com/0/1202552961248957/1208851110314077/f ### Description ### Steps to test this PR Smoke test Duck Player ### UI changes | Before | After | | ------ | ----- | !(Upload before screenshot)|(Upload after screenshot)|
1 parent 42b4545 commit 747c4af

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

duckplayer/duckplayer-impl/src/main/java/com/duckduckgo/duckplayer/impl/DuckPlayerLocalFilesPath.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
package com.duckduckgo.duckplayer.impl
1818

1919
import android.content.res.AssetManager
20+
import com.duckduckgo.app.di.AppCoroutineScope
21+
import com.duckduckgo.app.di.IsMainProcess
2022
import com.duckduckgo.common.utils.DispatcherProvider
2123
import com.duckduckgo.di.scopes.AppScope
2224
import com.squareup.anvil.annotations.ContributesBinding
2325
import dagger.SingleInstanceIn
2426
import javax.inject.Inject
25-
import kotlinx.coroutines.runBlocking
27+
import kotlinx.coroutines.CoroutineScope
28+
import kotlinx.coroutines.launch
2629

2730
interface DuckPlayerLocalFilesPath {
2831
fun assetsPath(): List<String>
@@ -33,9 +36,19 @@ interface DuckPlayerLocalFilesPath {
3336
class RealDuckPlayerLocalFilesPath @Inject constructor(
3437
private val assetManager: AssetManager,
3538
dispatcherProvider: DispatcherProvider,
39+
@AppCoroutineScope private val appCoroutineScope: CoroutineScope,
40+
@IsMainProcess private val isMainProcess: Boolean,
3641
) : DuckPlayerLocalFilesPath {
3742

38-
private val assetsPaths: List<String> = runBlocking(dispatcherProvider.io()) { getAllAssetFilePaths("duckplayer") }
43+
private var assetsPaths: List<String> = listOf()
44+
45+
init {
46+
if (isMainProcess) {
47+
appCoroutineScope.launch(dispatcherProvider.io()) {
48+
assetsPaths = getAllAssetFilePaths("duckplayer")
49+
}
50+
}
51+
}
3952

4053
override fun assetsPath(): List<String> = assetsPaths
4154

0 commit comments

Comments
 (0)