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

Commit 5590e58b authored by Hasib Prince's avatar Hasib Prince Committed by Sayantan Roychowdhury
Browse files

fixed: data corruption during auto update

parent 9dc05508
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ class DownloadManagerUtils @Inject constructor(
                    Timber.d("===> updateDownloadStatus: ${fusedDownload.name}: $downloadId: $numberOfDownloadedItems/${fusedDownload.downloadIdMap.size}")

                    if (validateDownload(numberOfDownloadedItems, fusedDownload, downloadId)) {
                        Timber.d("===> Download is completed for: ${fusedDownload.name}")
                        Timber.i("===> Download is completed for: ${fusedDownload.name}")
                        fusedManagerRepository.moveOBBFileToOBBDirectory(fusedDownload)
                        fusedDownload.status = Status.DOWNLOADED
                        fusedManagerRepository.updateFusedDownload(fusedDownload)
@@ -109,7 +109,7 @@ class DownloadManagerUtils @Inject constructor(
        }
        fusedDownload.status = Status.INSTALLATION_ISSUE
        fusedManagerRepository.updateFusedDownload(fusedDownload)
        Timber.d("CleanApk signature is Wrong!")
        Timber.w("CleanApk signature is Wrong!")
        return false
    }
}
+5 −4
Original line number Diff line number Diff line
@@ -34,18 +34,19 @@ class FusedManagerRepository @Inject constructor(
        return fusedManagerImpl.moveOBBFilesToOBBDirectory(fusedDownload)
    }

    suspend fun addDownload(fusedDownload: FusedDownload) {
    suspend fun addDownload(fusedDownload: FusedDownload): Boolean {
        if (InstallWorkManager.checkWorkIsAlreadyAvailable(fusedDownload.id)) {
            return
            return false
        }

        val existingFusedDownload = fusedManagerImpl.getDownloadById(fusedDownload)
        // We don't want to add any thing, if it already exists without INSTALLATION_ISSUE
        if (existingFusedDownload != null && existingFusedDownload.status != Status.INSTALLATION_ISSUE) {
            return
            return false
        }

        return fusedManagerImpl.addDownload(fusedDownload)
        fusedManagerImpl.addDownload(fusedDownload)
        return true
    }

    suspend fun addFusedDownloadPurchaseNeeded(fusedDownload: FusedDownload) {
+9 −4
Original line number Diff line number Diff line
@@ -109,9 +109,10 @@ class UpdatesWorker @AssistedInject constructor(
             * If user in UNAVAILABLE, don't do anything.
             */
            resultStatus = ResultStatus.OK
            Timber.w("User is not available! User is required during update!")
            return
        }

        Timber.i("Updates found: ${appsNeededToUpdate.size}; $resultStatus")
        if (isAutoUpdate && shouldShowNotification) {
            handleNotification(appsNeededToUpdate.size, isConnectedToUnmeteredNetwork)
        }
@@ -234,11 +235,15 @@ class UpdatesWorker @AssistedInject constructor(
                return@forEach
            }

            fusedManagerRepository.addDownload(fusedDownload)
            val isSuccess = fusedManagerRepository.addDownload(fusedDownload)
            if (!isSuccess) {
                Timber.i("Update adding ABORTED! status: $isSuccess")
                return@forEach
            }

            fusedManagerRepository.updateAwaiting(fusedDownload)
            Timber.d("startUpdateProcess: Enqueued for update: ${fusedDownload.name} ${fusedDownload.id} ${fusedDownload.status}")
            InstallWorkManager.enqueueWork(fusedDownload, true)
            Timber.i("startUpdateProcess: " + fusedDownload.name)
            Timber.i("startUpdateProcess: Enqueued for update: ${fusedDownload.name} ${fusedDownload.id} ${fusedDownload.status}")
        }
    }

+1 −3
Original line number Diff line number Diff line
@@ -4,8 +4,6 @@ enum class ResultStatus {
    OK,
    TIMEOUT,
    UNKNOWN,
    RETRY,
    ;

    RETRY;
    var message: String = ""
}