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

Commit 5ac7712a authored by Hasib Prince's avatar Hasib Prince
Browse files

Merge branch '1798-fix_crash' into 'main'

1798 fix crash

See merge request !414
parents 725dd01a fba5f984
Loading
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -173,8 +173,16 @@ class DownloadManager @Inject constructor(
        }
    }

    fun isDownloadSuccessful(downloadId: Long): Boolean {
        return getDownloadStatus(downloadId) == DownloadManager.STATUS_SUCCESSFUL
    /**
     * Checks download is successful or not.
     * @param downloadId is the id of a particular download request
     * @return Pair<Boolean, Int>, Where first represents success/failure,
     * second represents status.
     */
    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 {
+2 −21
Original line number Diff line number Diff line
@@ -169,28 +169,9 @@ object RetrofitModule {
                "User-Agent",
                "Dalvik/2.1.0 (Linux; U; Android ${Build.VERSION.RELEASE};)"
            ).header("Accept-Language", Locale.getDefault().language)
            try {

            return@Interceptor chain.proceed(builder.build())
            } catch (e: ConnectException) {
                return@Interceptor buildErrorResponse(e, chain)
            } catch (e: Exception) {
                return@Interceptor buildErrorResponse(e, chain)
            }
        }
        }

    private fun buildErrorResponse(
        e: Exception,
        chain: Interceptor.Chain
    ): Response {
        Timber.e("buildErrorResponse: ${e.localizedMessage}")
        return Response.Builder()
            .code(999)
            .message(e.localizedMessage ?: "Unknown error")
            .request(chain.request())
            .protocol(Protocol.HTTP_1_1)
            .body("{}".toResponseBody("application/json; charset=utf-8".toMediaTypeOrNull()))
            .build()
    }

    @Singleton
+12 −3
Original line number Diff line number Diff line
@@ -106,10 +106,19 @@ class DownloadManagerUtils @Inject constructor(
        numberOfDownloadedItems: Int,
        fusedDownload: FusedDownload,
        downloadId: Long
    ) = downloadManager.isDownloadSuccessful(downloadId) && areAllFilesDownloaded(
    ): Boolean {
        val isDownloadSuccessful = downloadManager.isDownloadSuccessful(downloadId)
        // if download status code is unknown (-1), consider installation is failed.
        if (isDownloadSuccessful.second == -1) {
            handleDownloadFailed(fusedDownload, downloadId)
        }

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

    }

    private fun areAllFilesDownloaded(
        numberOfDownloadedItems: Int,
        fusedDownload: FusedDownload
+3 −5
Original line number Diff line number Diff line
@@ -519,11 +519,9 @@ class ApplicationListRVAdapter(
                if (searchApp.is_pwa) {
                    mainActivityViewModel.launchPwa(searchApp)
                } else {
                    context.startActivity(
                        mainActivityViewModel.getLaunchIntentForPackageName(
                            searchApp.package_name
                        )
                    )
                    mainActivityViewModel.getLaunchIntentForPackageName(searchApp.package_name)?.let {
                        context.startActivity(it)
                    }
                }
            }
        }
+3 −2
Original line number Diff line number Diff line
@@ -204,8 +204,9 @@ class HomeFragment : TimeoutFragment(R.layout.fragment_home), ApplicationInstall
            viewHolder?.let { parentViewHolder ->
                val childRV =
                    (parentViewHolder as HomeParentRVAdapter.ViewHolder).binding.childRV
                val adapter = childRV.adapter as HomeChildRVAdapter
                findDownloadingItemsToShowProgress(adapter, downloadProgress, childRV)
                (childRV.adapter as HomeChildRVAdapter?)?.let {
                    findDownloadingItemsToShowProgress(it, downloadProgress, childRV)
                }
            }
        }
    }
Loading