瀏覽代碼

fix spotbugs and make PendingIntent immutable

Signed-off-by: Jonas Mayer <jonas.a.mayer@gmx.net>
Jonas Mayer 1 年之前
父節點
當前提交
a30592ec9f

+ 1 - 1
app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt

@@ -207,7 +207,7 @@ class FilesUploadWorker(
             context,
             context,
             SecureRandom().nextInt(),
             SecureRandom().nextInt(),
             notificationActionIntent,
             notificationActionIntent,
-            PendingIntent.FLAG_MUTABLE
+            PendingIntent.FLAG_IMMUTABLE
         )
         )
 
 
         notificationBuilder
         notificationBuilder

+ 6 - 2
app/src/main/java/com/owncloud/android/files/services/FileUploader.java

@@ -207,6 +207,8 @@ public class FileUploader extends Service
     private Account mCurrentAccount;
     private Account mCurrentAccount;
     private FileDataStorageManager mStorageManager;
     private FileDataStorageManager mStorageManager;
 
 
+    private SecureRandom secureRandomGenerator = new SecureRandom();
+
     @Inject UserAccountManager accountManager;
     @Inject UserAccountManager accountManager;
     @Inject UploadsStorageManager mUploadsStorageManager;
     @Inject UploadsStorageManager mUploadsStorageManager;
     @Inject ConnectivityService connectivityService;
     @Inject ConnectivityService connectivityService;
@@ -237,6 +239,7 @@ public class FileUploader extends Service
     /**
     /**
      * Service initialization
      * Service initialization
      */
      */
+    @SuppressFBWarnings("ST")
     @Override
     @Override
     public void onCreate() {
     public void onCreate() {
         super.onCreate();
         super.onCreate();
@@ -284,6 +287,7 @@ public class FileUploader extends Service
     /**
     /**
      * Service clean up
      * Service clean up
      */
      */
+    @SuppressFBWarnings("ST")
     @Override
     @Override
     public void onDestroy() {
     public void onDestroy() {
         Log_OC.v(TAG, "Destroying service");
         Log_OC.v(TAG, "Destroying service");
@@ -713,7 +717,7 @@ public class FileUploader extends Service
         notificationActionIntent.putExtra(EXTRA_REMOTE_PATH,upload.getRemotePath());
         notificationActionIntent.putExtra(EXTRA_REMOTE_PATH,upload.getRemotePath());
         notificationActionIntent.setAction(ACTION_CANCEL_BROADCAST);
         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;
         mLastPercent = 0;
         mNotificationBuilder = NotificationUtils.newNotificationBuilder(this, viewThemeUtils);
         mNotificationBuilder = NotificationUtils.newNotificationBuilder(this, viewThemeUtils);
         mNotificationBuilder
         mNotificationBuilder
@@ -869,7 +873,7 @@ public class FileUploader extends Service
 
 
             mNotificationBuilder.setContentText(content);
             mNotificationBuilder.setContentText(content);
             if (!uploadResult.isSuccess()) {
             if (!uploadResult.isSuccess()) {
-                mNotificationManager.notify((new SecureRandom()).nextInt(), mNotificationBuilder.build());
+                mNotificationManager.notify(secureRandomGenerator.nextInt(), mNotificationBuilder.build());
             }
             }
         }
         }
     }
     }