Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6150be6d authored by Hasib Prince's avatar Hasib Prince
Browse files

App Lounge: draft fix for update stuck

parent 825d89fd
Loading
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -64,10 +64,12 @@ class DownloadManagerUtils @Inject constructor(
                    )
                    if (downloaded == fusedDownload.downloadIdMap.size) {
                        fusedManagerRepository.moveOBBFileToOBBDirectory(fusedDownload)
                        fusedManagerRepository.updateDownloadStatus(
                            fusedDownload,
                            Status.INSTALLING
                        )
                        fusedDownload.status = Status.DOWNLOADED
                        fusedManagerRepository.updateFusedDownload(fusedDownload)
//                        fusedManagerRepository.updateDownloadStatus(
//                            fusedDownload,
//                            Status.INSTALLING
//                        )
                    }
                }
            }
+1 −0
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@ class FusedManagerImpl @Inject constructor(
                        Log.d(TAG, "installApp: ENDED ${fusedDownload.name} ${list.size}")
                    } catch (e: Exception) {
                        installationIssue(fusedDownload)
                        throw e
                    }
                }
            }
+32 −11
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.takeWhile
import kotlinx.coroutines.sync.Mutex
import java.lang.RuntimeException
import java.util.concurrent.atomic.AtomicInteger
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
@@ -59,6 +61,8 @@ class InstallAppWorker @AssistedInject constructor(
        private val atomicInteger = AtomicInteger(100)
    }

    private val mutex = Mutex(true)

    override suspend fun doWork(): Result {
        var fusedDownload: FusedDownload? = null
        try {
@@ -75,15 +79,19 @@ class InstallAppWorker @AssistedInject constructor(
                    )
                )
                startAppInstallationProcess(it)
                mutex.lock()
            }
            Log.d(TAG, "doWork: RESULT SUCCESS: ${fusedDownload?.name}")
            return Result.success()
//            Log.d(TAG, "doWork: RESULT SUCCESS: ${fusedDownload?.name}")
//            return Result.success()
        } catch (e: Exception) {
            Log.e(TAG, "doWork: Failed: ${e.stackTraceToString()}")
            fusedDownload?.let {
                fusedManagerRepository.installationIssue(it)
            }
            return Result.failure()
//            return Result.failure()
        } finally {
            Log.d(TAG, "doWork: RESULT SUCCESS: ${fusedDownload?.name}")
            return Result.success()
        }
    }

@@ -94,10 +102,10 @@ class InstallAppWorker @AssistedInject constructor(
        Log.d(TAG, "===> doWork: Download started ${fusedDownload.name} ${fusedDownload.status}")
        if (fusedDownload.type == Type.NATIVE) {
            isDownloading = true
            tickerFlow(1.seconds)
                .onEach {
                    checkDownloadProcess(fusedDownload)
                }.launchIn(CoroutineScope(Dispatchers.IO))
//            tickerFlow(1.seconds)
//                .onEach {
//                    checkDownloadProcess(fusedDownload)
//                }.launchIn(CoroutineScope(Dispatchers.IO))
            observeDownload(fusedDownload)
        }
    }
@@ -141,20 +149,29 @@ class InstallAppWorker @AssistedInject constructor(
            .collect { fusedDownload ->
                if (fusedDownload == null) {
                    isDownloading = false
                    mutex.unlock()
                    return@collect
                }
                Log.d(
                    TAG,
                    "doWork: flow collect ===> ${fusedDownload.name} ${fusedDownload.status}"
                )
                try {
                    handleFusedDownloadStatus(fusedDownload)
                } catch (e: Exception) {
                    Log.e(TAG, "observeDownload: ", e)
                    mutex.unlock()
                }
            }
    }

    private fun handleFusedDownloadStatus(fusedDownload: FusedDownload) {
    private suspend fun handleFusedDownloadStatus(fusedDownload: FusedDownload) {
        when (fusedDownload.status) {
            Status.AWAITING, Status.DOWNLOADING -> {
            }
            Status.DOWNLOADED -> {
                fusedManagerRepository.updateDownloadStatus(fusedDownload, Status.INSTALLING)
            }
            Status.INSTALLING -> {
                Log.d(
                    TAG,
@@ -165,8 +182,12 @@ class InstallAppWorker @AssistedInject constructor(
                isDownloading = false
                Log.d(
                    TAG,
                    "===> doWork: Installed/Failed started ${fusedDownload.name} ${fusedDownload.status}"
                    "===> doWork: Installed/Failed: ${fusedDownload.name} ${fusedDownload.status}"
                )
//                if(fusedDownload.status == Status.INSTALLATION_ISSUE) {
//                    throw RuntimeException("Installation error occurred")
//                }
                mutex.unlock()
            }
            else -> {
                isDownloading = false
+1 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ enum class Status {
    UPDATABLE,
    INSTALLING,
    DOWNLOADING,
    DOWNLOADED,
    UNAVAILABLE,
    UNINSTALLING,
    QUEUED,