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

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

NPE in downloadmanager is handled

parent 762f39fc
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -83,10 +83,18 @@ class DownloadManager @Inject constructor(
        downloadFile: File,
        downloadCompleted: ((Boolean, String) -> Unit)?
    ): Long {
        var downloadId = -1L
        try {
            val request = DownloadManager.Request(Uri.parse(url))
                .setTitle("Downloading...")
                .setDestinationUri(Uri.fromFile(downloadFile))
        val downloadId = downloadManager.enqueue(request)
            downloadId = downloadManager.enqueue(request)
        } catch (e: java.lang.NullPointerException) {
            Timber.e(e, "Url: $url; downloadFilePath: ${downloadFile.absolutePath}")
            downloadCompleted?.invoke(false, e.localizedMessage ?: "No message found!")
            return downloadId
        }

        downloadsMaps[downloadId] = true
        tickerFlow(downloadId, .5.seconds).onEach {
            checkDownloadProgress(downloadId, downloadFile.absolutePath, downloadCompleted)