Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions opencloudApp/src/main/java/eu/opencloud/android/MainApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin
import org.koin.core.context.stopKoin
import timber.log.Timber
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit

/**
* Main Application of the project
Expand Down Expand Up @@ -362,6 +364,9 @@ class MainApp : Application() {

const val PREFERENCE_KEY_LAST_SEEN_VERSION_CODE = "lastSeenVersionCode"

private const val DEPENDENCY_INJECTION_TIMEOUT_SECONDS = 10L
private val dependencyInjectionReady = CountDownLatch(1)

const val PREFERENCE_KEY_DONT_SHOW_SERVER_ACCOUNT_WARNING_DIALOG = "PREFERENCE_KEY_DONT_SHOW_SERVER_ACCOUNT_WARNING_DIALOG"

/**
Expand Down Expand Up @@ -413,6 +418,12 @@ class MainApp : Application() {
return String.format(appString, version)
}

fun awaitDependencyInjection() {
if (!dependencyInjectionReady.await(DEPENDENCY_INJECTION_TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
Timber.w("Dependency injection not ready after $DEPENDENCY_INJECTION_TIMEOUT_SECONDS s")
}
}

fun initDependencyInjection() {
stopKoin()
startKoin {
Expand All @@ -428,6 +439,7 @@ class MainApp : Application() {
)
)
}
dependencyInjectionReady.countDown()
}

fun getLastSeenVersionCode(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import androidx.work.WorkManager
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject
import org.koin.core.context.GlobalContext
import timber.log.Timber
import java.io.File
import java.io.FileNotFoundException
Expand Down Expand Up @@ -816,6 +816,12 @@ class DocumentsStorageProvider : DocumentsProvider() {
if (isVault(file)) throw UnsupportedOperationException("${file.remotePath} is an encrypted vault")
}

// Android may start the process for this provider and deliver binder calls before MainApp has started Koin
private inline fun <reified T : Any> inject(): Lazy<T> = lazy {
MainApp.awaitDependencyInjection()
GlobalContext.get().get<T>()
}

private fun getFileByIdOrException(id: Int): OCFile {
val getFileByIdUseCase: GetFileByIdUseCase by inject()
val result = getFileByIdUseCase(GetFileByIdUseCase.Params(id.toLong()))
Expand Down