Skip to content
Merged
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
3 changes: 0 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,6 @@
<receiver
android:name="com.nextcloud.client.jobs.NotificationWork$NotificationReceiver"
android:exported="false" />
<receiver
android:name="com.nextcloud.client.jobs.upload.FileUploadHelper$UploadNotificationActionReceiver"
android:exported="false" />
<receiver
android:name="com.nextcloud.client.widget.DashboardWidgetProvider"
android:exported="false">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface UploadDao {
"WHERE ${ProviderTableMeta.UPLOADS_ACCOUNT_NAME} = :accountName " +
"AND ${ProviderTableMeta.UPLOADS_REMOTE_PATH} = :remotePath"
)
fun deleteByAccountAndRemotePath(accountName: String, remotePath: String)
fun deleteByAccountAndRemotePath(remotePath: String, accountName: String)

@Query(
"SELECT * FROM " + ProviderTableMeta.UPLOADS_TABLE_NAME +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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
Expand All @@ -22,34 +21,55 @@ class FileUploadBroadcastReceiver : BroadcastReceiver() {
lateinit var uploadsStorageManager: UploadsStorageManager

companion object {
private const val UPLOAD_ID = "UPLOAD_ID"

fun getBroadcast(context: Context, id: Long): 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.toInt(),
intent,
PendingIntent.FLAG_IMMUTABLE
)
}
// region cancel or remove actions
const val UPLOAD_ID = "UPLOAD_ID"
const val ACCOUNT_NAME = "ACCOUNT_NAME"
const val REMOTE_PATH = "REMOTE_PATH"
const val REMOVE = "REMOVE"
// endregion
}

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

if (intent.action == UploadBroadcastAction.CancelOrRemove::class.simpleName) {
cancelUpload(context, intent)
}
}

@Suppress("ReturnCount")
private fun cancelUpload(context: Context, intent: Intent) {
val uploadId = intent.getLongExtra(UPLOAD_ID, -1L)
if (uploadId == -1L) {
return
}

uploadsStorageManager.removeUpload(uploadId)
val accountName = intent.getStringExtra(ACCOUNT_NAME)
if (accountName.isNullOrEmpty()) {
return
}

val remotePath = intent.getStringExtra(REMOTE_PATH)
if (remotePath.isNullOrEmpty()) {
return
}

val remove = intent.getBooleanExtra(REMOVE, false)

FileUploadWorker.cancelCurrentUpload(remotePath, accountName, onCompleted = {})

if (remove) {
uploadsStorageManager.removeUpload(uploadId)
} else {
FileUploadHelper.instance().updateUploadStatus(
remotePath,
accountName,
UploadsStorageManager.UploadStatus.UPLOAD_CANCELLED
)
}

// dismiss notification
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancel(uploadId.toInt())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class FileUploadHelper {
}

fun removeFileUpload(remotePath: String, accountName: String) {
uploadsStorageManager.uploadDao.deleteByAccountAndRemotePath(accountName, remotePath)
uploadsStorageManager.uploadDao.deleteByAccountAndRemotePath(remotePath, accountName)
}

fun updateUploadStatus(remotePath: String, accountName: String, status: UploadStatus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class FileUploadWorker(
if (preferences.isGlobalUploadPaused) {
Log_OC.d(TAG, "Upload is paused, skip uploading files!")
notificationManager.notifyPaused(
intents.notificationStartIntent(null)
intents.openUploadListIntent(null)
)
return@withContext Result.success()
}
Expand All @@ -256,8 +256,7 @@ class FileUploadWorker(
val currentUploadIndex = (currentIndex + previouslyUploadedFileSize)
notificationManager.prepareForStart(
operation,
cancelPendingIntent = intents.startIntent(operation),
startIntent = intents.notificationStartIntent(operation),
startIntent = intents.openUploadListIntent(operation),
currentUploadIndex = currentUploadIndex,
totalUploadSize = totalUploadSize
)
Expand Down Expand Up @@ -353,7 +352,7 @@ class FileUploadWorker(
Log_OC.e(TAG, "Error uploading", e)
result = RemoteOperationResult<Any?>(e)
} finally {
if (!isStopped || !result.isCancelled) {
if (!isStopped) {
uploadsStorageManager.updateDatabaseUploadResult(result, operation)
UploadErrorNotificationManager.handleResult(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,10 @@ import android.content.Context
import android.content.Intent
import com.owncloud.android.operations.UploadFileOperation
import com.owncloud.android.ui.activity.UploadListActivity
import java.security.SecureRandom

class FileUploaderIntents(private val context: Context) {

private val secureRandomGenerator = SecureRandom()

fun startIntent(operation: UploadFileOperation): PendingIntent {
val intent = Intent(
context,
FileUploadHelper.UploadNotificationActionReceiver::class.java
).apply {
putExtra(FileUploadWorker.EXTRA_ACCOUNT_NAME, operation.user.accountName)
putExtra(FileUploadWorker.EXTRA_REMOTE_PATH, operation.remotePath)
action = FileUploadWorker.ACTION_CANCEL_BROADCAST
}

return PendingIntent.getBroadcast(
context,
secureRandomGenerator.nextInt(),
intent,
PendingIntent.FLAG_IMMUTABLE
)
}

fun notificationStartIntent(operation: UploadFileOperation?): PendingIntent {
fun openUploadListIntent(operation: UploadFileOperation?): PendingIntent {
val intent = UploadListActivity.createIntent(
operation?.file,
operation?.user,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2025 Alper Ozturk <alper.ozturk@nextcloud.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

package com.nextcloud.client.jobs.upload

import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationCompat
import com.owncloud.android.R
import com.owncloud.android.operations.UploadFileOperation

sealed class UploadBroadcastAction {
data class CancelOrRemove(val operation: UploadFileOperation) : UploadBroadcastAction() {
fun cancelAction(context: Context): NotificationCompat.Action = NotificationCompat.Action(
R.drawable.ic_cancel,
context.getString(R.string.common_cancel),
getBroadcast(context, false)
)

fun removeAction(context: Context): NotificationCompat.Action = NotificationCompat.Action(
R.drawable.ic_delete,
context.getString(R.string.remove_upload),
getBroadcast(context, true)
)

@Suppress("MagicNumber")
private fun getBroadcast(context: Context, remove: Boolean): PendingIntent {
val intent = Intent(context, FileUploadBroadcastReceiver::class.java).apply {
putExtra(FileUploadBroadcastReceiver.UPLOAD_ID, operation.ocUploadId)
putExtra(FileUploadBroadcastReceiver.ACCOUNT_NAME, operation.user.accountName)
putExtra(FileUploadBroadcastReceiver.REMOTE_PATH, operation.remotePath)
putExtra(FileUploadBroadcastReceiver.REMOVE, remove)
action = CancelOrRemove::class.simpleName

setClass(context, FileUploadBroadcastReceiver::class.java)
setPackage(context.packageName)
}

val requestCode = if (remove) operation.ocUploadId.toInt() + 1000 else operation.ocUploadId.toInt()

return PendingIntent.getBroadcast(
context,
requestCode,
intent,
PendingIntent.FLAG_IMMUTABLE
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class UploadNotificationManager(private val context: Context, viewThemeUtils: Vi

@Suppress("MagicNumber")
fun prepareForStart(
uploadFileOperation: UploadFileOperation,
cancelPendingIntent: PendingIntent,
operation: UploadFileOperation,
startIntent: PendingIntent,
currentUploadIndex: Int,
totalUploadSize: Int
Expand All @@ -38,10 +37,10 @@ class UploadNotificationManager(private val context: Context, viewThemeUtils: Vi
context.getString(R.string.upload_notification_manager_start_text),
currentUploadIndex,
totalUploadSize,
uploadFileOperation.fileName
operation.fileName
)
} else {
uploadFileOperation.fileName
operation.fileName
}

val progressText = NumberFormatter.getPercentageText(0)
Expand All @@ -52,17 +51,12 @@ class UploadNotificationManager(private val context: Context, viewThemeUtils: Vi
setContentText(progressText)
setOngoing(false)
clearActions()

addAction(
R.drawable.ic_action_cancel_grey,
context.getString(R.string.common_cancel),
cancelPendingIntent
)

addAction(UploadBroadcastAction.CancelOrRemove(operation).cancelAction(context))
addAction(UploadBroadcastAction.CancelOrRemove(operation).removeAction(context))
setContentIntent(startIntent)
}

if (!uploadFileOperation.isInstantPicture && !uploadFileOperation.isInstantVideo) {
if (!operation.isInstantPicture && !operation.isInstantVideo) {
showNotification()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationCompat
import com.nextcloud.client.jobs.notification.WorkerNotificationManager
import com.nextcloud.client.jobs.upload.FileUploadBroadcastReceiver
import com.nextcloud.client.jobs.upload.FileUploadHelper
import com.nextcloud.client.jobs.upload.UploadBroadcastAction
import com.nextcloud.utils.extensions.isFileSpecificError
import com.owncloud.android.R
import com.owncloud.android.authentication.AuthenticatorActivity
Expand Down Expand Up @@ -100,13 +100,12 @@ object UploadErrorNotificationManager {
context.getString(R.string.upload_list_resolve_conflict),
conflictResolvePendingIntent(context, operation)
)
addAction(
R.drawable.ic_delete,
context.getString(R.string.upload_list_cancel_upload),
FileUploadBroadcastReceiver.getBroadcast(context, operation.ocUploadId)
)
}

addAction(UploadBroadcastAction.CancelOrRemove(operation).cancelAction(context))

addAction(UploadBroadcastAction.CancelOrRemove(operation).removeAction(context))

result.code.takeIf { it == ResultCode.UNAUTHORIZED }?.let {
setContentIntent(credentialPendingIntent(context, operation))
}
Expand All @@ -119,6 +118,7 @@ object UploadErrorNotificationManager {
else -> R.string.uploader_upload_failed_ticker
}

@Suppress("DEPRECATION")
private fun credentialPendingIntent(context: Context, operation: UploadFileOperation): PendingIntent {
val intent = Intent(context, AuthenticatorActivity::class.java).apply {
putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, operation.user.toPlatformAccount())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.adapter.progressListener.UploadProgressListener;
import com.owncloud.android.ui.notifications.NotificationUtils;
import com.owncloud.android.ui.preview.PreviewImageFragment;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.MimeTypeUtil;
Expand Down Expand Up @@ -1077,17 +1076,14 @@ public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
}

public void cancelOldErrorNotification(OCUpload upload) {

if (mNotificationManager == null) {
mNotificationManager = (NotificationManager) parentActivity.getSystemService(parentActivity.NOTIFICATION_SERVICE);
mNotificationManager = (NotificationManager) parentActivity.getSystemService(Context.NOTIFICATION_SERVICE);
}

if (upload == null) {
return;
}
mNotificationManager.cancel(NotificationUtils.createUploadNotificationTag(upload.getRemotePath(), upload.getLocalPath()),
FileUploadWorker.NOTIFICATION_ERROR_ID);

mNotificationManager.cancel((int) upload.getUploadId());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
*/
package com.owncloud.android.ui.notifications

import com.owncloud.android.datamodel.OCFile

object NotificationUtils {
const val NOTIFICATION_CHANNEL_GENERAL: String = "NOTIFICATION_CHANNEL_GENERAL"
const val NOTIFICATION_CHANNEL_DOWNLOAD: String = "NOTIFICATION_CHANNEL_DOWNLOAD"
Expand All @@ -25,9 +23,6 @@ object NotificationUtils {
const val NOTIFICATION_CHANNEL_OFFLINE_OPERATIONS: String = "NOTIFICATION_CHANNEL_OFFLINE_OPERATIONS"
const val NOTIFICATION_CHANNEL_CONTENT_OBSERVER: String = "NOTIFICATION_CHANNEL_CONTENT_OBSERVER"

fun createUploadNotificationTag(file: OCFile): String =
createUploadNotificationTag(file.remotePath, file.storagePath)

@JvmStatic
fun createUploadNotificationTag(remotePath: String?, localPath: String): String = remotePath + localPath
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,7 @@
<string name="secure_share_not_set_up">Secure sharing is not set up for this user</string>
<string name="share_not_allowed_when_file_drop">Resharing is not allowed during secure file drop</string>
<string name="prefs_category_sync">Sync</string>
<string name="remove_upload">Remove</string>
<string name="internal_two_way_sync">Internal two way sync</string>
<string name="prefs_two_way_sync_summary">Manage internal folders for two way sync</string>
<string name="internal_two_way_sync_not_yet">Not yet, soon to be synced</string>
Expand Down
Loading