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

Verified Commit 6eb9b8ef authored by Fahim M. Choudhury's avatar Fahim M. Choudhury
Browse files

feat: implement centralized install/update failure path

parent 2ce05edd
Loading
Loading
Loading
Loading
+23 −9
Original line number Diff line number Diff line
@@ -152,14 +152,8 @@ class AppManagerImpl @Inject constructor(
            appInstallRepository.deleteDownload(appInstall)
        } else if (status == Status.INSTALLING) {
            appInstall.downloadIdMap.all { true }
            appInstall.status = status
            val isSelfUpdate = appInstall.packageName == context.packageName
            if (isSelfUpdate) {
                appInstallRepository.deleteDownload(appInstall)
            } else {
            appInstall.status = status
            appInstallRepository.updateDownload(appInstall)
            }
            installApp(appInstall)
        }
    }
@@ -195,7 +189,7 @@ class AppManagerImpl @Inject constructor(
                list.sort()

                if (list.isEmpty()) {
                    reportInstallationIssue(appInstall)
                    finalizeUnattendedFailure(appInstall)
                    val errorMessage =
                        "installApp: Downloaded files doesn't exist for package ${appInstall.packageName} "
                    Timber.e(errorMessage)
@@ -214,7 +208,7 @@ class AppManagerImpl @Inject constructor(
                    Timber.d("installApp: ENDED ${appInstall.name} ${list.size}")
                } catch (e: Exception) {
                    Timber.e(">>> installApp app failed ${e.localizedMessage}")
                    reportInstallationIssue(appInstall)
                    finalizeUnattendedFailure(appInstall)
                    throw e
                }
            }
@@ -238,6 +232,26 @@ class AppManagerImpl @Inject constructor(
        }
    }

    override suspend fun finalizeUnattendedFailure(appInstall: AppInstall) {
        mutex.withLock {
            Timber.w(
                "Finalizing unattended failure for %s (%s) with %d tracked downloads",
                appInstall.name,
                appInstall.packageName,
                appInstall.downloadIdMap.size
            )
            appInstall.downloadIdMap.forEach { (key, _) ->
                downloadManager.remove(key)
            }
            DownloadProgressLD.setDownloadId(-1)

            appInstall.downloadIdMap = mutableMapOf()
            appInstall.status = Status.INSTALLATION_ISSUE
            appInstallRepository.updateDownload(appInstall)
            flushOldDownload(appInstall.packageName)
        }
    }

    private suspend fun removeFusedDownload(appInstall: AppInstall) {
        appInstall.downloadIdMap.forEach { (key, _) ->
            downloadManager.remove(key)
+1 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ class InstallationEnqueuer @Inject constructor(
                        "Enqueuing App install work is failed for ${appInstall.packageName} " +
                            "exception: ${throwable.localizedMessage}"
                    )
                    appManager.reportInstallationIssue(appInstall)
                    appManager.finalizeUnattendedFailure(appInstall)
                    false
                }
                else -> throw throwable
+1 −2
Original line number Diff line number Diff line
@@ -96,8 +96,7 @@ class DownloadManagerUtils @Inject constructor(
    }

    private suspend fun handleDownloadFailed(appInstall: AppInstall, downloadId: Long) {
        appManager.reportInstallationIssue(appInstall)
        appManager.cancelDownload(appInstall)
        appManager.finalizeUnattendedFailure(appInstall)
        Timber.w("===> Download failed: ${appInstall.name} ${appInstall.status}")

        val hasInsufficientSpace =
+6 −1
Original line number Diff line number Diff line
@@ -135,10 +135,15 @@ class InstallerService : Service() {
    private fun updateInstallationIssue(pkgName: String) {
        if (pkgName.isEmpty()) {
            Timber.d("updateDownloadStatus: package name should not be empty!")
            return
        }
        coroutineScope.launch {
            val fusedDownload = appManager.getFusedDownload(packageName = pkgName)
            appManager.reportInstallationIssue(fusedDownload)
            if (fusedDownload.id.isEmpty()) {
                Timber.w("Unable to finalize install failure for unresolved package %s", pkgName)
                return@launch
            }
            appManager.finalizeUnattendedFailure(fusedDownload)
        }
    }
}
+5 −1
Original line number Diff line number Diff line
@@ -109,7 +109,11 @@ class PkgManagerBR @Inject constructor(
    private fun updateInstallationIssue(pkgName: String) {
        coroutineScope.launch {
            val fusedDownload = appManager.getFusedDownload(packageName = pkgName)
            appManager.reportInstallationIssue(fusedDownload)
            if (fusedDownload.id.isEmpty()) {
                Timber.w("Unable to finalize broadcast install failure for unresolved package %s", pkgName)
                return@launch
            }
            appManager.finalizeUnattendedFailure(fusedDownload)
        }
    }
}
Loading