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 @@ -179,7 +179,8 @@ class BackgroundJobFactory @Inject constructor(
powerManagementService = powerManagementService,
syncedFolderProvider = syncedFolderProvider,
backgroundJobManager = backgroundJobManager.get(),
repository = FileSystemRepository(dao = database.fileSystemDao())
repository = FileSystemRepository(dao = database.fileSystemDao()),
viewThemeUtils = viewThemeUtils.get()
)

private fun createOfflineSyncWork(context: Context, params: WorkerParameters): OfflineSyncWork = OfflineSyncWork(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2025 Alper Ozturk <[email protected]>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

package com.nextcloud.client.jobs.autoUpload

import android.content.Context
import com.nextcloud.client.jobs.notification.WorkerNotificationManager
import com.owncloud.android.R
import com.owncloud.android.ui.notifications.NotificationUtils
import com.owncloud.android.utils.theme.ViewThemeUtils

class AutoUploadNotificationManager(context: Context, viewThemeUtils: ViewThemeUtils, id: Int) :
WorkerNotificationManager(
id,
context,
viewThemeUtils,
tickerId = R.string.foreground_service_upload,
channelId = NotificationUtils.NOTIFICATION_CHANNEL_UPLOAD
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
package com.nextcloud.client.jobs.autoUpload

import android.app.Notification
import android.app.NotificationManager
import android.content.Context
import android.content.res.Resources
import androidx.core.app.NotificationCompat
import androidx.exifinterface.media.ExifInterface
import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters
Expand All @@ -23,6 +21,7 @@ import com.nextcloud.client.database.entity.toUploadEntity
import com.nextcloud.client.device.PowerManagementService
import com.nextcloud.client.jobs.BackgroundJobManager
import com.nextcloud.client.jobs.upload.FileUploadWorker
import com.nextcloud.client.jobs.utils.UploadErrorNotificationManager
import com.nextcloud.client.network.ConnectivityService
import com.nextcloud.client.preferences.SubFolderRule
import com.nextcloud.utils.ForegroundServiceHelper
Expand All @@ -41,10 +40,10 @@ import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.operations.UploadFileOperation
import com.owncloud.android.ui.activity.SettingsActivity
import com.owncloud.android.ui.notifications.NotificationUtils
import com.owncloud.android.utils.FileStorageUtils
import com.owncloud.android.utils.FilesSyncHelper
import com.owncloud.android.utils.MimeType
import com.owncloud.android.utils.theme.ViewThemeUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.File
Expand All @@ -63,24 +62,21 @@ class AutoUploadWorker(
private val powerManagementService: PowerManagementService,
private val syncedFolderProvider: SyncedFolderProvider,
private val backgroundJobManager: BackgroundJobManager,
private val repository: FileSystemRepository
private val repository: FileSystemRepository,
val viewThemeUtils: ViewThemeUtils
) : CoroutineWorker(context, params) {

companion object {
const val TAG = "🔄📤" + "AutoUpload"
const val OVERRIDE_POWER_SAVING = "overridePowerSaving"
const val CONTENT_URIS = "content_uris"
const val SYNCED_FOLDER_ID = "syncedFolderId"
private const val CHANNEL_ID = NotificationUtils.NOTIFICATION_CHANNEL_UPLOAD

private const val NOTIFICATION_ID = 266
const val NOTIFICATION_ID = 266
}

private val helper = AutoUploadHelper()
private lateinit var syncedFolder: SyncedFolder
private val notificationManager by lazy {
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
}
private val notificationManager = AutoUploadNotificationManager(context, viewThemeUtils, NOTIFICATION_ID)

@Suppress("TooGenericExceptionCaught", "ReturnCount")
override suspend fun doWork(): Result {
Expand Down Expand Up @@ -124,7 +120,7 @@ class AutoUploadWorker(
)
)

notificationManager.notify(NOTIFICATION_ID, startNotification)
notificationManager.showNotification(startNotification)
}
}

Expand All @@ -137,7 +133,7 @@ class AutoUploadWorker(
setForeground(foregroundInfo)
}

private fun createNotification(title: String): Notification = NotificationCompat.Builder(context, CHANNEL_ID)
private fun createNotification(title: String): Notification = notificationManager.notificationBuilder
.setContentTitle(title)
.setSmallIcon(R.drawable.uploads)
.setOngoing(true)
Expand Down Expand Up @@ -259,7 +255,7 @@ class AutoUploadWorker(
SettingsActivity.SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI
)
val uploadActionString = context.resources.getString(R.string.syncedFolder_light_upload_behaviour)
val uploadAction = getUploadAction(uploadActionString)
val uploadAction = FileUploadWorker.getUploadAction(uploadActionString)
Log_OC.d(TAG, "upload action is: $uploadAction")
Triple(needsCharging, needsWifi, uploadAction)
} else {
Expand Down Expand Up @@ -314,6 +310,13 @@ class AutoUploadWorker(
val result = operation.execute(client)
uploadsStorageManager.updateStatus(uploadEntity, result.isSuccess)

UploadErrorNotificationManager.handleResult(
context,
notificationManager,
operation,
result
)

if (result.isSuccess) {
repository.markFileAsUploaded(localPath, syncedFolder)
Log_OC.d(TAG, "✅ upload completed: $localPath")
Expand Down Expand Up @@ -470,11 +473,4 @@ class AutoUploadWorker(
}
return lastModificationTime
}

private fun getUploadAction(action: String): Int = when (action) {
"LOCAL_BEHAVIOUR_FORGET" -> FileUploadWorker.Companion.LOCAL_BEHAVIOUR_FORGET
"LOCAL_BEHAVIOUR_MOVE" -> FileUploadWorker.Companion.LOCAL_BEHAVIOUR_MOVE
"LOCAL_BEHAVIOUR_DELETE" -> FileUploadWorker.Companion.LOCAL_BEHAVIOUR_DELETE
else -> FileUploadWorker.Companion.LOCAL_BEHAVIOUR_FORGET
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ open class WorkerNotificationManager(
notificationManager.notify(id, notificationBuilder.build())
}

fun showNotification(notification: Notification) {
notificationManager.notify(id, notification)

Check failure

Code scanning / CodeQL

Use of implicit PendingIntents

[An implicit Intent is created](1) and sent to an unspecified third party through a PendingIntent. [An implicit Intent is created](2) and sent to an unspecified third party through a PendingIntent. [An implicit Intent is created](3) and sent to an unspecified third party through a PendingIntent.

Copilot Autofix

AI about 15 hours ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

Check failure

Code scanning / CodeQL

Use of implicit PendingIntents

[An implicit Intent is created](1) and sent to an unspecified third party through a PendingIntent. [An implicit Intent is created](2) and sent to an unspecified third party through a PendingIntent. [An implicit Intent is created](3) and sent to an unspecified third party through a PendingIntent.

Copilot Autofix

AI about 15 hours ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

}

fun showNotification(id: Int, notification: Notification) {
notificationManager.notify(id, notification)
}

@Suppress("MagicNumber")
fun setProgress(percent: Int, progressText: String?, indeterminate: Boolean) {
notificationBuilder.run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
package com.nextcloud.client.jobs.upload

import android.app.NotificationManager
import android.app.PendingIntent
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.owncloud.android.MainApp
import com.owncloud.android.datamodel.UploadsStorageManager
import com.owncloud.android.ui.notifications.NotificationUtils
import javax.inject.Inject

class FileUploadBroadcastReceiver : BroadcastReceiver() {
Expand All @@ -22,27 +22,35 @@ class FileUploadBroadcastReceiver : BroadcastReceiver() {
lateinit var uploadsStorageManager: UploadsStorageManager

companion object {
const val UPLOAD_ID = "UPLOAD_ID"
const val REMOTE_PATH = "REMOTE_PATH"
const val STORAGE_PATH = "STORAGE_PATH"
private const val UPLOAD_ID = "UPLOAD_ID"

fun getBroadcast(context: Context, id: Int): PendingIntent {
val intent = Intent(context, FileUploadBroadcastReceiver::class.java).apply {
putExtra(UPLOAD_ID, id)
setClass(context, FileUploadBroadcastReceiver::class.java)
setPackage(context.packageName)
}

return PendingIntent.getBroadcast(
context,
id,
intent,
PendingIntent.FLAG_IMMUTABLE
)
}
}

@Suppress("ReturnCount")
override fun onReceive(context: Context, intent: Intent) {
MainApp.getAppComponent().inject(this)

val remotePath = intent.getStringExtra(REMOTE_PATH) ?: return
val storagePath = intent.getStringExtra(STORAGE_PATH) ?: return
val uploadId = intent.getLongExtra(UPLOAD_ID, -1L)
if (uploadId == -1L) {
return
}

uploadsStorageManager.removeUpload(uploadId)
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancel(
NotificationUtils.createUploadNotificationTag(remotePath, storagePath),
FileUploadWorker.NOTIFICATION_ERROR_ID
)
notificationManager.cancel(uploadId.toInt())
}
}
Loading
Loading