Skip to content

Commit

Permalink
Fix ANR in DuckPlayerLocalFilesPath (#5340)
Browse files Browse the repository at this point in the history
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)|
  • Loading branch information
CrisBarreiro authored Dec 10, 2024
1 parent 42b4545 commit 747c4af
Showing 1 changed file with 15 additions and 2 deletions.
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

0 comments on commit 747c4af

Please sign in to comment.