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

Commit ee6a8faf authored by Hasib Prince's avatar Hasib Prince
Browse files

handled unknown download status

parent 1442b301
Loading
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -173,12 +173,15 @@ class DownloadManager @Inject constructor(
        }
    }

    fun isDownloadSuccessful(downloadId: Long): Boolean {
        return getDownloadStatus(downloadId) == DownloadManager.STATUS_SUCCESSFUL
    fun isDownloadSuccessful(downloadId: Long): Pair<Boolean, Int> {
        val downloadStatus = getDownloadStatus(downloadId)
        val isSuccessFul = downloadStatus == DownloadManager.STATUS_SUCCESSFUL
        return Pair(isSuccessFul, downloadStatus)
    }

    fun hasDownloadFailed(downloadId: Long): Boolean {
        return getDownloadStatus(downloadId) == DownloadManager.STATUS_FAILED
        val downloadStatus = getDownloadStatus(downloadId)
        return downloadStatus == DownloadManager.STATUS_FAILED
    }

    fun getSizeRequired(downloadId: Long): Long {
+1 −1
Original line number Diff line number Diff line
@@ -185,7 +185,7 @@ object RetrofitModule {
    ): Response {
        Timber.e("buildErrorResponse: ${e.localizedMessage}")
        return Response.Builder()
            .code(999)
            .code(403)
            .message(e.localizedMessage ?: "Unknown error")
            .request(chain.request())
            .protocol(Protocol.HTTP_1_1)
+11 −3
Original line number Diff line number Diff line
@@ -106,10 +106,18 @@ class DownloadManagerUtils @Inject constructor(
        numberOfDownloadedItems: Int,
        fusedDownload: FusedDownload,
        downloadId: Long
    ) = downloadManager.isDownloadSuccessful(downloadId) && areAllFilesDownloaded(
    ): Boolean {
        val isDownloadSuccessful = downloadManager.isDownloadSuccessful(downloadId)
        if (isDownloadSuccessful.second == -1) {
            handleDownloadFailed(fusedDownload, downloadId)
        }

        return isDownloadSuccessful.first && areAllFilesDownloaded(
            numberOfDownloadedItems, fusedDownload
        ) && checkCleanApkSignatureOK(fusedDownload)

    }

    private fun areAllFilesDownloaded(
        numberOfDownloadedItems: Int,
        fusedDownload: FusedDownload