Revision control
Copy as Markdown
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
package org.mozilla.reference.browser.downloads
import android.os.Environment
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.feature.downloads.AbstractFetchDownloadService
import mozilla.components.feature.downloads.DefaultPackageNameProvider
import mozilla.components.feature.downloads.DownloadEstimator
import mozilla.components.feature.downloads.FileSizeFormatter
import mozilla.components.feature.downloads.PackageNameProvider
import mozilla.components.feature.downloads.filewriter.DefaultDownloadFileWriter
import mozilla.components.feature.downloads.filewriter.DownloadFileWriter
import mozilla.components.support.base.android.NotificationsDelegate
import mozilla.components.support.utils.DefaultDownloadFileUtils
import mozilla.components.support.utils.DownloadFileUtils
import org.mozilla.reference.browser.ext.components
/** Runs downloads in a foreground service so they continue after the user leaves the app. */
class DownloadService : AbstractFetchDownloadService() {
override val httpClient by lazy { components.core.client }
override val store: BrowserStore by lazy { components.core.store }
override val notificationsDelegate: NotificationsDelegate by lazy { components.notificationsDelegate }
override val fileSizeFormatter: FileSizeFormatter by lazy { components.fileSizeFormatter }
override val downloadEstimator: DownloadEstimator by lazy { components.downloadEstimator }
override val downloadFileUtils: DownloadFileUtils by lazy {
DefaultDownloadFileUtils(
context = applicationContext,
downloadLocation = {
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).path
},
)
}
override val downloadFileWriter: DownloadFileWriter by lazy {
DefaultDownloadFileWriter(
context = applicationContext,
downloadFileUtils = downloadFileUtils,
)
}
override val packageNameProvider: PackageNameProvider by lazy { DefaultPackageNameProvider(applicationContext) }
}