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

Commit 487b77f9 authored by Nihar Thakkar's avatar Nihar Thakkar
Browse files

Continue downloading apps only after installation of current app is complete

parent 1954481f
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ class Application(val packageName: String, private val applicationManager: Appli
    val state: State
        get() = stateManager.state
    var downloader: Downloader? = null
    private val blocker = Object()

    fun incrementUses() {
        uses.incrementAndGet()
@@ -100,6 +101,9 @@ class Application(val packageName: String, private val applicationManager: Appli
            downloader = Downloader(info, fullData!!, this)
            stateManager.notifyDownloading(downloader!!)
            downloader!!.download(context)
            synchronized(blocker) {
                blocker.wait()
            }
        } else {
            stateManager.notifyError(error)
            onDownloadComplete(context, DownloadManager.STATUS_FAILED)
@@ -110,6 +114,9 @@ class Application(val packageName: String, private val applicationManager: Appli
        if (status == DownloadManager.STATUS_SUCCESSFUL) {
            install(context)
        } else {
            synchronized(blocker) {
                blocker.notify()
            }
            info.getApkFile(context, basicData!!).delete()
            applicationManager.stopInstalling(context, this)
        }
@@ -121,8 +128,10 @@ class Application(val packageName: String, private val applicationManager: Appli
    }

    override fun onInstallationComplete(context: Context) {
        synchronized(blocker) {
            blocker.notify()
        }
        info.getApkFile(context, basicData!!).delete()
        applicationManager.stopInstalling(context, this)
    }

    fun isUsed(): Boolean {
+3 −1
Original line number Diff line number Diff line
@@ -42,7 +42,9 @@ class Downloader(private val applicationInfo: ApplicationInfo, private val fullD
            registerReceivers(context)
            initialiseDownloadManagerRequest(context)
            downloadId = downloadManager.enqueue(request)
            Thread {
                handleDownloadUpdates()
            }.start()
        } else {
            downloaderInterface.onDownloadComplete(context, DownloadManager.STATUS_FAILED)
        }