From 197ba1c43b63b500f05535357892774a6d397c8d Mon Sep 17 00:00:00 2001 From: Jonas Mayer Date: Tue, 21 Nov 2023 18:58:09 +0100 Subject: [PATCH 1/4] add cancel button to upload notification Signed-off-by: Jonas Mayer --- app/src/main/AndroidManifest.xml | 3 ++ .../client/jobs/FilesUploadWorker.kt | 13 +++++ .../datamodel/UploadsStorageManager.java | 18 +++++++ .../android/files/services/FileUploader.java | 49 +++++++++++++++++-- .../android/utils/FilesUploadHelper.kt | 2 - 5 files changed, 80 insertions(+), 5 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 349d5da8a935..7d630b2a6938 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -166,6 +166,9 @@ + diff --git a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt index 3f38a80f2c56..1bf7f861662a 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt @@ -43,6 +43,7 @@ import com.owncloud.android.datamodel.FileDataStorageManager import com.owncloud.android.datamodel.ThumbnailsCacheManager import com.owncloud.android.datamodel.UploadsStorageManager import com.owncloud.android.db.OCUpload +import com.owncloud.android.files.services.FileUploader import com.owncloud.android.lib.common.OwnCloudAccount import com.owncloud.android.lib.common.OwnCloudClientManagerFactory import com.owncloud.android.lib.common.network.OnDatatransferProgressListener @@ -200,6 +201,14 @@ class FilesUploadWorker( * adapted from [com.owncloud.android.files.services.FileUploader.notifyUploadStart] */ private fun createNotification(uploadFileOperation: UploadFileOperation) { + + val notificationActionIntent = Intent(context,FileUploader.UploadNotificationActionReceiver::class.java) + notificationActionIntent.putExtra(FileUploader.EXTRA_ACCOUNT_NAME,uploadFileOperation.user.accountName) + notificationActionIntent.putExtra(FileUploader.EXTRA_REMOTE_PATH,uploadFileOperation.remotePath) + notificationActionIntent.action = FileUploader.ACTION_CANCEL_BROADCAST + + val pendingIntent = PendingIntent.getBroadcast(context,SecureRandom().nextInt(),notificationActionIntent, PendingIntent.FLAG_MUTABLE) + notificationBuilder .setOngoing(true) .setSmallIcon(R.drawable.notification_icon) @@ -212,6 +221,9 @@ class FilesUploadWorker( uploadFileOperation.fileName ) ) + .clearActions() // to make sure there is only one action + .addAction(R.drawable.ic_action_cancel_grey,context.getString(R.string.common_cancel),pendingIntent) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { notificationBuilder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_UPLOAD) @@ -278,6 +290,7 @@ class FilesUploadWorker( .setAutoCancel(true) .setOngoing(false) .setProgress(0, 0, false) + .clearActions() val content = ErrorMessageAdapter.getErrorCauseMessage(uploadResult, uploadFileOperation, context.resources) diff --git a/app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java b/app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java index 0aac8b984abe..d188c9523b86 100644 --- a/app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java +++ b/app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java @@ -345,6 +345,24 @@ public OCUpload[] getAllStoredUploads() { return getUploads(null, (String[]) null); } + public OCUpload getUploadByRemotePath(String remotePath){ + OCUpload result = null; + Cursor cursor = getDB().query( + ProviderTableMeta.CONTENT_URI_UPLOADS, + null, + ProviderTableMeta.UPLOADS_REMOTE_PATH + "=?", + new String[]{remotePath}, + ProviderTableMeta.UPLOADS_REMOTE_PATH+ " ASC"); + + if (cursor != null) { + if (cursor.moveToFirst()) { + result = createOCUploadFromCursor(cursor); + } + } + Log_OC.d(TAG, "Retrieve job " + result + " for remote path " + remotePath); + return result; + } + public @Nullable OCUpload getUploadById(long id) { OCUpload result = null; diff --git a/app/src/main/java/com/owncloud/android/files/services/FileUploader.java b/app/src/main/java/com/owncloud/android/files/services/FileUploader.java index 1c1f70d105a9..a54026260e85 100644 --- a/app/src/main/java/com/owncloud/android/files/services/FileUploader.java +++ b/app/src/main/java/com/owncloud/android/files/services/FileUploader.java @@ -34,6 +34,7 @@ import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; +import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.graphics.BitmapFactory; @@ -127,6 +128,10 @@ public class FileUploader extends Service public static final String EXTRA_LINKED_TO_PATH = "LINKED_TO"; public static final String ACCOUNT_NAME = "ACCOUNT_NAME"; + public static final String EXTRA_ACCOUNT_NAME = "ACCOUNT_NAME"; + public static final String ACTION_CANCEL_BROADCAST = "CANCEL"; + public static final String ACTION_PAUSE_BROADCAST = "PAUSE"; + private static final int FOREGROUND_SERVICE_ID = 411; public static final String KEY_FILE = "FILE"; @@ -197,7 +202,7 @@ public class FileUploader extends Service private Notification mNotification; private Looper mServiceLooper; private ServiceHandler mServiceHandler; - private IBinder mBinder; + private static IBinder mBinder; private OwnCloudClient mUploadClient; private Account mCurrentAccount; private FileDataStorageManager mStorageManager; @@ -703,6 +708,12 @@ private Optional getCurrentUser() { */ private void notifyUploadStart(UploadFileOperation upload) { // / create status notification with a progress bar + Intent notificationActionIntent = new Intent(getApplicationContext(),UploadNotificationActionReceiver.class); + notificationActionIntent.putExtra(EXTRA_ACCOUNT_NAME,upload.getUser().getAccountName()); + notificationActionIntent.putExtra(EXTRA_REMOTE_PATH,upload.getRemotePath()); + notificationActionIntent.setAction(ACTION_CANCEL_BROADCAST); + + PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(),new SecureRandom().nextInt(),notificationActionIntent, PendingIntent.FLAG_MUTABLE); mLastPercent = 0; mNotificationBuilder = NotificationUtils.newNotificationBuilder(this, viewThemeUtils); mNotificationBuilder @@ -713,7 +724,10 @@ private void notifyUploadStart(UploadFileOperation upload) { .setProgress(100, 0, false) .setContentText( String.format(getString(R.string.uploader_upload_in_progress_content), 0, upload.getFileName()) - ); + ) + .clearActions() // to make sure there is only one action + .addAction(R.drawable.ic_action_cancel_grey,getApplicationContext().getString(R.string.common_cancel),pendingIntent); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { mNotificationBuilder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_UPLOAD); @@ -806,7 +820,8 @@ private void notifyUploadResult(UploadFileOperation upload, RemoteOperationResul .setContentTitle(getString(tickerId)) .setAutoCancel(true) .setOngoing(false) - .setProgress(0, 0, false); + .setProgress(0, 0, false) + .clearActions(); content = ErrorMessageAdapter.getErrorCauseMessage(uploadResult, upload, getResources()); @@ -1403,4 +1418,32 @@ public void handleMessage(Message msg) { mService.stopSelf(msg.arg1); } } + + + /** + * When cancel action in upload notification is pressed, cancel upload of item + */ + public static class UploadNotificationActionReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + + String accountName = intent.getStringExtra(EXTRA_ACCOUNT_NAME); + String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH); + String action = intent.getAction(); + + if (ACTION_CANCEL_BROADCAST.equals(action)) { + Log_OC.d(TAG, "Cancel broadcast received for file " + remotePath + " at " + System.currentTimeMillis()); + + if (accountName == null || remotePath == null) return; + + FileUploaderBinder uploadBinder = (FileUploaderBinder) mBinder; + uploadBinder.cancel(accountName, remotePath, null); + }else if(ACTION_PAUSE_BROADCAST.equals(action)){ + + } else { + Log_OC.d(TAG, "Unknown action to perform as UploadNotificationActionReceiver."); + } + } + } } diff --git a/app/src/main/java/com/owncloud/android/utils/FilesUploadHelper.kt b/app/src/main/java/com/owncloud/android/utils/FilesUploadHelper.kt index a86f5bee9b98..b153c9c6c89d 100644 --- a/app/src/main/java/com/owncloud/android/utils/FilesUploadHelper.kt +++ b/app/src/main/java/com/owncloud/android/utils/FilesUploadHelper.kt @@ -90,8 +90,6 @@ class FilesUploadHelper { - - fun uploadUpdatedFile( user: User, existingFiles: Array, From 7f01cb51ff3eefafdec1951239a390ecd0d5b1fe Mon Sep 17 00:00:00 2001 From: Jonas Mayer Date: Tue, 21 Nov 2023 18:58:09 +0100 Subject: [PATCH 2/4] add cancel button to upload notification Signed-off-by: Jonas Mayer --- app/src/main/AndroidManifest.xml | 3 ++ .../client/jobs/FilesUploadWorker.kt | 13 +++++ .../datamodel/UploadsStorageManager.java | 18 +++++++ .../android/files/services/FileUploader.java | 49 +++++++++++++++++-- 4 files changed, 80 insertions(+), 3 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 349d5da8a935..7d630b2a6938 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -166,6 +166,9 @@ + diff --git a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt index 3ae67640a3f7..6bceef8a05d6 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt @@ -43,6 +43,7 @@ import com.owncloud.android.datamodel.FileDataStorageManager import com.owncloud.android.datamodel.ThumbnailsCacheManager import com.owncloud.android.datamodel.UploadsStorageManager import com.owncloud.android.db.OCUpload +import com.owncloud.android.files.services.FileUploader import com.owncloud.android.lib.common.OwnCloudAccount import com.owncloud.android.lib.common.OwnCloudClientManagerFactory import com.owncloud.android.lib.common.network.OnDatatransferProgressListener @@ -197,6 +198,14 @@ class FilesUploadWorker( * adapted from [com.owncloud.android.files.services.FileUploader.notifyUploadStart] */ private fun createNotification(uploadFileOperation: UploadFileOperation) { + + val notificationActionIntent = Intent(context,FileUploader.UploadNotificationActionReceiver::class.java) + notificationActionIntent.putExtra(FileUploader.EXTRA_ACCOUNT_NAME,uploadFileOperation.user.accountName) + notificationActionIntent.putExtra(FileUploader.EXTRA_REMOTE_PATH,uploadFileOperation.remotePath) + notificationActionIntent.action = FileUploader.ACTION_CANCEL_BROADCAST + + val pendingIntent = PendingIntent.getBroadcast(context,SecureRandom().nextInt(),notificationActionIntent, PendingIntent.FLAG_MUTABLE) + notificationBuilder .setOngoing(true) .setSmallIcon(R.drawable.notification_icon) @@ -209,6 +218,9 @@ class FilesUploadWorker( uploadFileOperation.fileName ) ) + .clearActions() // to make sure there is only one action + .addAction(R.drawable.ic_action_cancel_grey,context.getString(R.string.common_cancel),pendingIntent) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { notificationBuilder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_UPLOAD) @@ -275,6 +287,7 @@ class FilesUploadWorker( .setAutoCancel(true) .setOngoing(false) .setProgress(0, 0, false) + .clearActions() val content = ErrorMessageAdapter.getErrorCauseMessage(uploadResult, uploadFileOperation, context.resources) diff --git a/app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java b/app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java index 0aac8b984abe..d188c9523b86 100644 --- a/app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java +++ b/app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java @@ -345,6 +345,24 @@ public OCUpload[] getAllStoredUploads() { return getUploads(null, (String[]) null); } + public OCUpload getUploadByRemotePath(String remotePath){ + OCUpload result = null; + Cursor cursor = getDB().query( + ProviderTableMeta.CONTENT_URI_UPLOADS, + null, + ProviderTableMeta.UPLOADS_REMOTE_PATH + "=?", + new String[]{remotePath}, + ProviderTableMeta.UPLOADS_REMOTE_PATH+ " ASC"); + + if (cursor != null) { + if (cursor.moveToFirst()) { + result = createOCUploadFromCursor(cursor); + } + } + Log_OC.d(TAG, "Retrieve job " + result + " for remote path " + remotePath); + return result; + } + public @Nullable OCUpload getUploadById(long id) { OCUpload result = null; diff --git a/app/src/main/java/com/owncloud/android/files/services/FileUploader.java b/app/src/main/java/com/owncloud/android/files/services/FileUploader.java index 64236d95fd22..28a64c5d978c 100644 --- a/app/src/main/java/com/owncloud/android/files/services/FileUploader.java +++ b/app/src/main/java/com/owncloud/android/files/services/FileUploader.java @@ -34,6 +34,7 @@ import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; +import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.graphics.BitmapFactory; @@ -127,6 +128,10 @@ public class FileUploader extends Service public static final String EXTRA_LINKED_TO_PATH = "LINKED_TO"; public static final String ACCOUNT_NAME = "ACCOUNT_NAME"; + public static final String EXTRA_ACCOUNT_NAME = "ACCOUNT_NAME"; + public static final String ACTION_CANCEL_BROADCAST = "CANCEL"; + public static final String ACTION_PAUSE_BROADCAST = "PAUSE"; + private static final int FOREGROUND_SERVICE_ID = 411; public static final String KEY_FILE = "FILE"; @@ -197,7 +202,7 @@ public class FileUploader extends Service private Notification mNotification; private Looper mServiceLooper; private ServiceHandler mServiceHandler; - private IBinder mBinder; + private static IBinder mBinder; private OwnCloudClient mUploadClient; private Account mCurrentAccount; private FileDataStorageManager mStorageManager; @@ -703,6 +708,12 @@ private Optional getCurrentUser() { */ private void notifyUploadStart(UploadFileOperation upload) { // / create status notification with a progress bar + Intent notificationActionIntent = new Intent(getApplicationContext(),UploadNotificationActionReceiver.class); + notificationActionIntent.putExtra(EXTRA_ACCOUNT_NAME,upload.getUser().getAccountName()); + notificationActionIntent.putExtra(EXTRA_REMOTE_PATH,upload.getRemotePath()); + notificationActionIntent.setAction(ACTION_CANCEL_BROADCAST); + + PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(),new SecureRandom().nextInt(),notificationActionIntent, PendingIntent.FLAG_MUTABLE); mLastPercent = 0; mNotificationBuilder = NotificationUtils.newNotificationBuilder(this, viewThemeUtils); mNotificationBuilder @@ -713,7 +724,10 @@ private void notifyUploadStart(UploadFileOperation upload) { .setProgress(100, 0, false) .setContentText( String.format(getString(R.string.uploader_upload_in_progress_content), 0, upload.getFileName()) - ); + ) + .clearActions() // to make sure there is only one action + .addAction(R.drawable.ic_action_cancel_grey,getApplicationContext().getString(R.string.common_cancel),pendingIntent); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { mNotificationBuilder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_UPLOAD); @@ -806,7 +820,8 @@ private void notifyUploadResult(UploadFileOperation upload, RemoteOperationResul .setContentTitle(getString(tickerId)) .setAutoCancel(true) .setOngoing(false) - .setProgress(0, 0, false); + .setProgress(0, 0, false) + .clearActions(); content = ErrorMessageAdapter.getErrorCauseMessage(uploadResult, upload, getResources()); @@ -1403,4 +1418,32 @@ public void handleMessage(Message msg) { mService.stopSelf(msg.arg1); } } + + + /** + * When cancel action in upload notification is pressed, cancel upload of item + */ + public static class UploadNotificationActionReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + + String accountName = intent.getStringExtra(EXTRA_ACCOUNT_NAME); + String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH); + String action = intent.getAction(); + + if (ACTION_CANCEL_BROADCAST.equals(action)) { + Log_OC.d(TAG, "Cancel broadcast received for file " + remotePath + " at " + System.currentTimeMillis()); + + if (accountName == null || remotePath == null) return; + + FileUploaderBinder uploadBinder = (FileUploaderBinder) mBinder; + uploadBinder.cancel(accountName, remotePath, null); + }else if(ACTION_PAUSE_BROADCAST.equals(action)){ + + } else { + Log_OC.d(TAG, "Unknown action to perform as UploadNotificationActionReceiver."); + } + } + } } From 2a3d698b20d5b2e169048868f68d1814eba8aa87 Mon Sep 17 00:00:00 2001 From: Jonas Mayer Date: Wed, 29 Nov 2023 10:36:55 +0100 Subject: [PATCH 3/4] fix kotlin format violations and remove unused function Signed-off-by: Jonas Mayer --- .../nextcloud/client/jobs/FilesUploadWorker.kt | 17 ++++++++++------- .../datamodel/UploadsStorageManager.java | 18 ------------------ 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt index 6bceef8a05d6..e174eb9d057c 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt @@ -198,13 +198,17 @@ class FilesUploadWorker( * adapted from [com.owncloud.android.files.services.FileUploader.notifyUploadStart] */ private fun createNotification(uploadFileOperation: UploadFileOperation) { - - val notificationActionIntent = Intent(context,FileUploader.UploadNotificationActionReceiver::class.java) - notificationActionIntent.putExtra(FileUploader.EXTRA_ACCOUNT_NAME,uploadFileOperation.user.accountName) - notificationActionIntent.putExtra(FileUploader.EXTRA_REMOTE_PATH,uploadFileOperation.remotePath) + val notificationActionIntent = Intent(context, FileUploader.UploadNotificationActionReceiver::class.java) + notificationActionIntent.putExtra(FileUploader.EXTRA_ACCOUNT_NAME, uploadFileOperation.user.accountName) + notificationActionIntent.putExtra(FileUploader.EXTRA_REMOTE_PATH, uploadFileOperation.remotePath) notificationActionIntent.action = FileUploader.ACTION_CANCEL_BROADCAST - val pendingIntent = PendingIntent.getBroadcast(context,SecureRandom().nextInt(),notificationActionIntent, PendingIntent.FLAG_MUTABLE) + val pendingIntent = PendingIntent.getBroadcast( + context, + SecureRandom().nextInt(), + notificationActionIntent, + PendingIntent.FLAG_MUTABLE + ) notificationBuilder .setOngoing(true) @@ -219,8 +223,7 @@ class FilesUploadWorker( ) ) .clearActions() // to make sure there is only one action - .addAction(R.drawable.ic_action_cancel_grey,context.getString(R.string.common_cancel),pendingIntent) - + .addAction(R.drawable.ic_action_cancel_grey, context.getString(R.string.common_cancel), pendingIntent) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { notificationBuilder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_UPLOAD) diff --git a/app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java b/app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java index d188c9523b86..0aac8b984abe 100644 --- a/app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java +++ b/app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java @@ -345,24 +345,6 @@ public OCUpload[] getAllStoredUploads() { return getUploads(null, (String[]) null); } - public OCUpload getUploadByRemotePath(String remotePath){ - OCUpload result = null; - Cursor cursor = getDB().query( - ProviderTableMeta.CONTENT_URI_UPLOADS, - null, - ProviderTableMeta.UPLOADS_REMOTE_PATH + "=?", - new String[]{remotePath}, - ProviderTableMeta.UPLOADS_REMOTE_PATH+ " ASC"); - - if (cursor != null) { - if (cursor.moveToFirst()) { - result = createOCUploadFromCursor(cursor); - } - } - Log_OC.d(TAG, "Retrieve job " + result + " for remote path " + remotePath); - return result; - } - public @Nullable OCUpload getUploadById(long id) { OCUpload result = null; From a30592ec9fd8886f75c8a97effd3ca17de6071b5 Mon Sep 17 00:00:00 2001 From: Jonas Mayer Date: Wed, 29 Nov 2023 23:50:33 +0100 Subject: [PATCH 4/4] fix spotbugs and make PendingIntent immutable Signed-off-by: Jonas Mayer --- .../java/com/nextcloud/client/jobs/FilesUploadWorker.kt | 2 +- .../com/owncloud/android/files/services/FileUploader.java | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt index e174eb9d057c..5f7a4c0fcb10 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt @@ -207,7 +207,7 @@ class FilesUploadWorker( context, SecureRandom().nextInt(), notificationActionIntent, - PendingIntent.FLAG_MUTABLE + PendingIntent.FLAG_IMMUTABLE ) notificationBuilder diff --git a/app/src/main/java/com/owncloud/android/files/services/FileUploader.java b/app/src/main/java/com/owncloud/android/files/services/FileUploader.java index 28a64c5d978c..5188965e81b9 100644 --- a/app/src/main/java/com/owncloud/android/files/services/FileUploader.java +++ b/app/src/main/java/com/owncloud/android/files/services/FileUploader.java @@ -207,6 +207,8 @@ public class FileUploader extends Service private Account mCurrentAccount; private FileDataStorageManager mStorageManager; + private SecureRandom secureRandomGenerator = new SecureRandom(); + @Inject UserAccountManager accountManager; @Inject UploadsStorageManager mUploadsStorageManager; @Inject ConnectivityService connectivityService; @@ -237,6 +239,7 @@ public void onRenameUpload() { /** * Service initialization */ + @SuppressFBWarnings("ST") @Override public void onCreate() { super.onCreate(); @@ -284,6 +287,7 @@ private void resurrection() { /** * Service clean up */ + @SuppressFBWarnings("ST") @Override public void onDestroy() { Log_OC.v(TAG, "Destroying service"); @@ -713,7 +717,7 @@ private void notifyUploadStart(UploadFileOperation upload) { notificationActionIntent.putExtra(EXTRA_REMOTE_PATH,upload.getRemotePath()); notificationActionIntent.setAction(ACTION_CANCEL_BROADCAST); - PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(),new SecureRandom().nextInt(),notificationActionIntent, PendingIntent.FLAG_MUTABLE); + PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(),secureRandomGenerator.nextInt(),notificationActionIntent, PendingIntent.FLAG_IMMUTABLE); mLastPercent = 0; mNotificationBuilder = NotificationUtils.newNotificationBuilder(this, viewThemeUtils); mNotificationBuilder @@ -869,7 +873,7 @@ private void notifyUploadResult(UploadFileOperation upload, RemoteOperationResul mNotificationBuilder.setContentText(content); if (!uploadResult.isSuccess()) { - mNotificationManager.notify((new SecureRandom()).nextInt(), mNotificationBuilder.build()); + mNotificationManager.notify(secureRandomGenerator.nextInt(), mNotificationBuilder.build()); } } }