From 8bf657ce27533a94718b71f018ebba31bd0b9643 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Tue, 23 Feb 2021 09:18:18 +0100 Subject: [PATCH] replace Random with SecureRandom and ignore Spotbugs warnign about randomness (just creating Notification IDs) Signed-off-by: Andy Scherzinger --- .../com/owncloud/android/files/services/FileDownloader.java | 6 ++++-- .../com/owncloud/android/files/services/FileUploader.java | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/owncloud/android/files/services/FileDownloader.java b/src/main/java/com/owncloud/android/files/services/FileDownloader.java index 9e83750bf6..5a596d21ad 100644 --- a/src/main/java/com/owncloud/android/files/services/FileDownloader.java +++ b/src/main/java/com/owncloud/android/files/services/FileDownloader.java @@ -69,11 +69,11 @@ import com.owncloud.android.utils.MimeTypeUtil; import com.owncloud.android.utils.theme.ThemeColorUtils; import java.io.File; +import java.security.SecureRandom; import java.util.AbstractList; import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import java.util.Random; import java.util.Vector; import javax.inject.Inject; @@ -81,6 +81,7 @@ import javax.inject.Inject; import androidx.core.app.NotificationCompat; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import dagger.android.AndroidInjection; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; public class FileDownloader extends Service implements OnDatatransferProgressListener, OnAccountsUpdateListener { @@ -614,6 +615,7 @@ public class FileDownloader extends Service * @param downloadResult Result of the download operation. * @param download Finished download operation */ + @SuppressFBWarnings("DMI") private void notifyDownloadResult(DownloadFileOperation download, RemoteOperationResult downloadResult) { if (mNotificationManager == null) { @@ -653,7 +655,7 @@ public class FileDownloader extends Service download, getResources())); if (mNotificationManager != null) { - mNotificationManager.notify((new Random()).nextInt(), mNotificationBuilder.build()); + mNotificationManager.notify((new SecureRandom()).nextInt(), mNotificationBuilder.build()); // Remove success notification if (downloadResult.isSuccess()) { diff --git a/src/main/java/com/owncloud/android/files/services/FileUploader.java b/src/main/java/com/owncloud/android/files/services/FileUploader.java index d1158c0beb..48ac3ca8dc 100644 --- a/src/main/java/com/owncloud/android/files/services/FileUploader.java +++ b/src/main/java/com/owncloud/android/files/services/FileUploader.java @@ -80,11 +80,11 @@ import com.owncloud.android.utils.ErrorMessageAdapter; import com.owncloud.android.utils.theme.ThemeColorUtils; import java.io.File; +import java.security.SecureRandom; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Random; import javax.annotation.Nullable; import javax.inject.Inject; @@ -93,6 +93,7 @@ import androidx.annotation.NonNull; import androidx.core.app.NotificationCompat; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import dagger.android.AndroidInjection; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; /** * Service for uploading files. Invoke using context.startService(...). @@ -745,6 +746,7 @@ public class FileUploader extends Service * @param uploadResult Result of the upload operation. * @param upload Finished upload operation */ + @SuppressFBWarnings("DMI") private void notifyUploadResult(UploadFileOperation upload, RemoteOperationResult uploadResult) { Log_OC.d(TAG, "NotifyUploadResult with resultCode: " + uploadResult.getCode()); // cancelled operation or success -> silent removal of progress notification @@ -826,7 +828,7 @@ public class FileUploader extends Service mNotificationBuilder.setContentText(content); if(!uploadResult.isSuccess()){ - mNotificationManager.notify((new Random()).nextInt(), mNotificationBuilder.build()); + mNotificationManager.notify((new SecureRandom()).nextInt(), mNotificationBuilder.build()); } }