Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ANR in DuckPlayerLocalFilesPath #5340

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
package com.duckduckgo.duckplayer.impl

import android.content.res.AssetManager
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.di.IsMainProcess
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.di.scopes.AppScope
import com.squareup.anvil.annotations.ContributesBinding
import dagger.SingleInstanceIn
import javax.inject.Inject
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

interface DuckPlayerLocalFilesPath {
fun assetsPath(): List<String>
Expand All @@ -33,9 +36,19 @@ interface DuckPlayerLocalFilesPath {
class RealDuckPlayerLocalFilesPath @Inject constructor(
private val assetManager: AssetManager,
dispatcherProvider: DispatcherProvider,
@AppCoroutineScope private val appCoroutineScope: CoroutineScope,
@IsMainProcess private val isMainProcess: Boolean,
) : DuckPlayerLocalFilesPath {

private val assetsPaths: List<String> = runBlocking(dispatcherProvider.io()) { getAllAssetFilePaths("duckplayer") }
private var assetsPaths: List<String> = listOf()

init {
if (isMainProcess) {
appCoroutineScope.launch(dispatcherProvider.io()) {
assetsPaths = getAllAssetFilePaths("duckplayer")
}
}
}

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

Expand Down
Loading