Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class FileMenuFilterIT : AbstractIT() {
MockKAnnotations.init(this)
every { mockFileUploaderBinder.isUploading(any(), any()) } returns false
every { mockComponentsGetter.fileUploaderHelper } returns mockFileUploaderBinder
every { mockFileDownloadProgressListener.isDownloading(any(), any()) } returns false

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isDownloading left over from foreground services no need this since worker is used

every { mockComponentsGetter.fileDownloadProgressListener } returns mockFileDownloadProgressListener
every { mockOperationsServiceBinder.isSynchronizing(any(), any()) } returns false
every { mockComponentsGetter.operationsServiceBinder } returns mockOperationsServiceBinder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ import com.owncloud.android.R
import com.owncloud.android.operations.DownloadFileOperation
import com.owncloud.android.ui.notifications.NotificationUtils
import com.owncloud.android.utils.theme.ViewThemeUtils
import java.io.File
import java.security.SecureRandom

@Suppress("TooManyFunctions")
@Suppress("TooManyFunctions", "MagicNumber")
class DownloadNotificationManager(id: Int, private val context: Context, viewThemeUtils: ViewThemeUtils) :
WorkerNotificationManager(
id,
Expand All @@ -29,11 +28,8 @@ class DownloadNotificationManager(id: Int, private val context: Context, viewThe
channelId = NotificationUtils.NOTIFICATION_CHANNEL_DOWNLOAD
) {

private var lastPercent = -1

@Suppress("MagicNumber")
fun prepareForStart(operation: DownloadFileOperation) {
currentOperationTitle = File(operation.savePath).name
currentOperationTitle = operation.file.fileName

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uses file name


notificationBuilder.run {
setContentTitle(currentOperationTitle)
Expand All @@ -51,20 +47,12 @@ class DownloadNotificationManager(id: Int, private val context: Context, viewThe
.setProgress(0, 0, false)
}

@Suppress("MagicNumber")
fun updateDownloadProgress(percent: Int, totalToTransfer: Long) {
// If downloads are so fast, no need to notify again.
if (percent == lastPercent) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already outer call have this

return
}
lastPercent = percent

val progressText = NumberFormatter.getPercentageText(percent)
setProgress(percent, progressText, totalToTransfer < 0)
showNotification()
}

@Suppress("MagicNumber")
fun dismissNotification() {
dismissNotification(2000)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2023 Alper Ozturk <alper.ozturk@nextcloud.com>
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH
* SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
* SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package com.nextcloud.client.jobs.download

Expand Down Expand Up @@ -42,6 +41,7 @@ import com.owncloud.android.utils.theme.ViewThemeUtils
import java.util.AbstractList
import java.util.Optional
import java.util.Vector
import java.util.concurrent.ConcurrentHashMap
import kotlin.random.Random

@Suppress("LongParameterList", "TooManyFunctions", "TooGenericExceptionCaught")
Expand Down Expand Up @@ -105,8 +105,6 @@ class FileDownloadWorker(

@Suppress("ReturnCount")
override suspend fun doWork(): Result {
trySetForeground()

return try {
setUser()
val remotePath = inputData.keyValueMap[FILE_REMOTE_PATH] as? String? ?: return Result.failure()
Expand Down Expand Up @@ -144,20 +142,21 @@ class FileDownloadWorker(
)
}

private suspend fun trySetForeground() {
private suspend fun trySetForeground(filename: String) {
try {
val foregroundInfo = createWorkerForegroundInfo()
val foregroundInfo = createWorkerForegroundInfo(filename)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes empty notification

setForeground(foregroundInfo)
} catch (e: Exception) {
Log_OC.w(TAG, "⚠️ Could not set foreground service: ${e.message}")
}
}

private fun createWorkerForegroundInfo(): ForegroundInfo = ForegroundServiceHelper.createWorkerForegroundInfo(
notificationManager.getId(),
notificationManager.getNotification(),
ForegroundServiceType.DataSync
)
private fun createWorkerForegroundInfo(filename: String): ForegroundInfo =
ForegroundServiceHelper.createWorkerForegroundInfo(
notificationManager.getId(),
notificationManager.getNotification(filename),
ForegroundServiceType.DataSync
)

private fun removePendingDownload(accountName: String?) {
pendingDownloads.remove(accountName)
Expand Down Expand Up @@ -188,7 +187,6 @@ class FileDownloadWorker(
)

operation.addDownloadDataTransferProgressListener(this)
operation.addDownloadDataTransferProgressListener(downloadProgressListener)
val (downloadKey, _) = pendingDownloads.putIfAbsent(
user?.accountName,
file.remotePath,
Expand Down Expand Up @@ -246,7 +244,7 @@ class FileDownloadWorker(
}

@Suppress("TooGenericExceptionCaught", "DEPRECATION")
private fun downloadFile(downloadKey: String) {
private suspend fun downloadFile(downloadKey: String) {
currentDownload = pendingDownloads.get(downloadKey)

if (currentDownload == null) {
Expand All @@ -262,6 +260,7 @@ class FileDownloadWorker(
}

lastPercent = 0
trySetForeground(currentDownload?.file?.fileName ?: "")
notificationManager.run {
prepareForStart(currentDownload!!)
setContentIntent(intents.detailsIntent(currentDownload!!), PendingIntent.FLAG_IMMUTABLE)
Expand Down Expand Up @@ -401,7 +400,7 @@ class FileDownloadWorker(
totalToTransfer: Long,
filePath: String
) {
val percent: Int = downloadProgressListener.getPercent(totalTransferredSoFar, totalToTransfer)
val percent: Int = getPercent(totalTransferredSoFar, totalToTransfer)
val currentTime = System.currentTimeMillis()

if (percent != lastPercent && (currentTime - lastUpdateTime) >= minProgressUpdateInterval) {
Expand All @@ -413,13 +412,11 @@ class FileDownloadWorker(

lastPercent = percent
EventBusFactory.downloadProgressEventBus.post(FileDownloadProgressEvent(percent))
downloadProgressListener.onTransferProgress(progressRate, totalTransferredSoFar, totalToTransfer, filePath)
}

// CHECK: Is this class still needed after conversion from Foreground Services to Worker?
inner class FileDownloadProgressListener : OnDatatransferProgressListener {
private val boundListeners: MutableMap<Long, OnDatatransferProgressListener> = HashMap()

fun isDownloading(user: User?, file: OCFile?): Boolean = FileDownloadHelper.instance().isDownloading(user, file)
private val boundListeners = ConcurrentHashMap<Long, OnDatatransferProgressListener>()

fun addDataTransferProgressListener(listener: OnDatatransferProgressListener?, file: OCFile?) {
if (file == null || listener == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ open class WorkerNotificationManager(

fun getNotification(): Notification = notificationBuilder.build()

fun getNotification(title: String): Notification {
notificationBuilder.setContentTitle(title)
return notificationBuilder.build()
}

fun getForegroundInfo(notification: Notification): ForegroundInfo =
ForegroundServiceHelper.createWorkerForegroundInfo(
id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {

String tmpFolder = getTmpFolder();

downloadOperation = new DownloadFileRemoteOperation(file.getRemotePath(), tmpFolder);
downloadOperation = new DownloadFileRemoteOperation(file.getRemotePath(), tmpFolder, file.getFileLength());

if (downloadType == DownloadType.DOWNLOAD) {
dataTransferListeners.forEach(downloadOperation::addProgressListener);
Expand All @@ -209,8 +209,6 @@ protected RemoteOperationResult run(OwnCloudClient client) {
NextcloudClient nextcloudClient = OwnCloudClientExtensionsKt.toNextcloudClient(client, operationContext);
result = downloadOperation.execute(nextcloudClient);



if (result.isSuccess()) {
modificationTimestamp = downloadOperation.getModificationTimestamp();
etag = downloadOperation.getEtag();
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
androidCommonLibraryVersion = "0.33.2"
androidGifDrawableVersion = "1.2.31"
androidImageCropperVersion = "4.7.0"
androidLibraryVersion ="1f476c0ab14fb280172be2aefd70db80e50bb17b"
androidLibraryVersion ="db0b541a73"
androidOpensslVersion = "3.5.6"
androidPluginVersion = "9.2.1"
androidsvgVersion = "1.4"
Expand Down
8 changes: 8 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21902,6 +21902,14 @@
<sha256 value="af2c66e6fa0f282bb91b53849ff2af8aba66ed301269aa9a71783af49a0e99f4" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="db0b541a73">
<artifact name="android-library-db0b541a73.aar">
<sha256 value="c61f2d42b0bd2464c62deed46d43462873e8b672946813d94abcad7939889f87" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
<artifact name="android-library-db0b541a73.module">
<sha256 value="3ec2dc73c701a153dcb19f4f19c0a19cee78682f8c17d6d357d511718e134efc" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="db3f2b5ebedf6d45314886ef420b4750cac09792">
<artifact name="android-library-db3f2b5ebedf6d45314886ef420b4750cac09792.aar">
<sha256 value="a13742e2776a3d00c46aefa47bdaa6b690db77ee69081c6a8a12ca7e48b57cf7" origin="Generated by Gradle" reason="Artifact is not signed"/>
Expand Down
Loading