mirror of
https://github.com/nextcloud/android.git
synced 2024-11-29 18:59:18 +03:00
Merge pull request #13073 from nextcloud/bugfix/fix-rare-lateinit-crash-on-file-download-worker
Bugfix Fix Rare lateinit Crash on File Download Worker
This commit is contained in:
commit
1c52ce37ac
2 changed files with 7 additions and 15 deletions
|
@ -556,7 +556,6 @@ internal class BackgroundJobManagerImpl(
|
||||||
val tag = startFileDownloadJobTag(user, file.fileId)
|
val tag = startFileDownloadJobTag(user, file.fileId)
|
||||||
|
|
||||||
val data = workDataOf(
|
val data = workDataOf(
|
||||||
FileDownloadWorker.WORKER_ID to file.fileId.toInt(),
|
|
||||||
FileDownloadWorker.ACCOUNT_NAME to user.accountName,
|
FileDownloadWorker.ACCOUNT_NAME to user.accountName,
|
||||||
FileDownloadWorker.FILE_REMOTE_PATH to file.remotePath,
|
FileDownloadWorker.FILE_REMOTE_PATH to file.remotePath,
|
||||||
FileDownloadWorker.BEHAVIOUR to behaviour,
|
FileDownloadWorker.BEHAVIOUR to behaviour,
|
||||||
|
|
|
@ -43,7 +43,7 @@ import java.util.Vector
|
||||||
|
|
||||||
@Suppress("LongParameterList", "TooManyFunctions")
|
@Suppress("LongParameterList", "TooManyFunctions")
|
||||||
class FileDownloadWorker(
|
class FileDownloadWorker(
|
||||||
private val viewThemeUtils: ViewThemeUtils,
|
viewThemeUtils: ViewThemeUtils,
|
||||||
private val accountManager: UserAccountManager,
|
private val accountManager: UserAccountManager,
|
||||||
private var localBroadcastManager: LocalBroadcastManager,
|
private var localBroadcastManager: LocalBroadcastManager,
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
|
@ -65,7 +65,6 @@ class FileDownloadWorker(
|
||||||
return pendingDownloads.all.any { it.value?.payload?.isMatching(accountName, fileId) == true }
|
return pendingDownloads.all.any { it.value?.payload?.isMatching(accountName, fileId) == true }
|
||||||
}
|
}
|
||||||
|
|
||||||
const val WORKER_ID = "WORKER_ID"
|
|
||||||
const val FILE_REMOTE_PATH = "FILE_REMOTE_PATH"
|
const val FILE_REMOTE_PATH = "FILE_REMOTE_PATH"
|
||||||
const val ACCOUNT_NAME = "ACCOUNT_NAME"
|
const val ACCOUNT_NAME = "ACCOUNT_NAME"
|
||||||
const val BEHAVIOUR = "BEHAVIOUR"
|
const val BEHAVIOUR = "BEHAVIOUR"
|
||||||
|
@ -94,7 +93,12 @@ class FileDownloadWorker(
|
||||||
private var lastPercent = 0
|
private var lastPercent = 0
|
||||||
|
|
||||||
private val intents = FileDownloadIntents(context)
|
private val intents = FileDownloadIntents(context)
|
||||||
private lateinit var notificationManager: DownloadNotificationManager
|
private var notificationManager = DownloadNotificationManager(
|
||||||
|
SecureRandom().nextInt(),
|
||||||
|
context,
|
||||||
|
viewThemeUtils
|
||||||
|
)
|
||||||
|
|
||||||
private var downloadProgressListener = FileDownloadProgressListener()
|
private var downloadProgressListener = FileDownloadProgressListener()
|
||||||
|
|
||||||
private var user: User? = null
|
private var user: User? = null
|
||||||
|
@ -103,20 +107,12 @@ class FileDownloadWorker(
|
||||||
private var currentUserFileStorageManager: FileDataStorageManager? = null
|
private var currentUserFileStorageManager: FileDataStorageManager? = null
|
||||||
private var fileDataStorageManager: FileDataStorageManager? = null
|
private var fileDataStorageManager: FileDataStorageManager? = null
|
||||||
|
|
||||||
private var workerId: Int? = null
|
|
||||||
private var downloadError: FileDownloadError? = null
|
private var downloadError: FileDownloadError? = null
|
||||||
|
|
||||||
@Suppress("TooGenericExceptionCaught")
|
@Suppress("TooGenericExceptionCaught")
|
||||||
override fun doWork(): Result {
|
override fun doWork(): Result {
|
||||||
return try {
|
return try {
|
||||||
val requestDownloads = getRequestDownloads()
|
val requestDownloads = getRequestDownloads()
|
||||||
|
|
||||||
notificationManager =
|
|
||||||
DownloadNotificationManager(
|
|
||||||
workerId ?: SecureRandom().nextInt(),
|
|
||||||
context,
|
|
||||||
viewThemeUtils
|
|
||||||
)
|
|
||||||
addAccountUpdateListener()
|
addAccountUpdateListener()
|
||||||
|
|
||||||
val foregroundInfo = ForegroundServiceHelper.createWorkerForegroundInfo(
|
val foregroundInfo = ForegroundServiceHelper.createWorkerForegroundInfo(
|
||||||
|
@ -170,9 +166,6 @@ class FileDownloadWorker(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getRequestDownloads(): AbstractList<String> {
|
private fun getRequestDownloads(): AbstractList<String> {
|
||||||
workerId = inputData.keyValueMap[WORKER_ID] as Int
|
|
||||||
Log_OC.e(TAG, "FilesDownloadWorker started for $workerId")
|
|
||||||
|
|
||||||
setUser()
|
setUser()
|
||||||
val files = getFiles()
|
val files = getFiles()
|
||||||
val downloadType = getDownloadType()
|
val downloadType = getDownloadType()
|
||||||
|
|
Loading…
Reference in a new issue