Selaa lähdekoodia

Make more PendingIntents immutable

This should be all of them. Picked up by lint.

Signed-off-by: Álvaro Brey Vilas <alvaro.brey@nextcloud.com>
Álvaro Brey Vilas 3 vuotta sitten
vanhempi
commit
c01fa0b170

+ 1 - 1
src/main/java/com/nextcloud/client/integrations/deck/DeckApiImpl.java

@@ -78,7 +78,7 @@ public class DeckApiImpl implements DeckApi {
         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         return PendingIntent.getActivity(context, notification.getNotificationId(),
                                          putExtrasToIntent(intent, notification, user),
-                                         PendingIntent.FLAG_ONE_SHOT);
+                                         PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);
     }
 
     private Intent putExtrasToIntent(@NonNull Intent intent, @NonNull Notification notification, @NonNull User user) {

+ 9 - 3
src/main/java/com/nextcloud/client/jobs/MediaFoldersDetectionWork.kt

@@ -184,6 +184,7 @@ class MediaFoldersDetectionWork constructor(
         return Result.success()
     }
 
+    @Suppress("LongMethod")
     private fun sendNotification(contentTitle: String, subtitle: String, user: User, path: String, type: Int) {
         val notificationId = randomIdGenerator.nextInt()
         val context = context
@@ -193,7 +194,12 @@ class MediaFoldersDetectionWork constructor(
         intent.putExtra(NotificationWork.KEY_NOTIFICATION_ACCOUNT, user.accountName)
         intent.putExtra(KEY_MEDIA_FOLDER_PATH, path)
         intent.putExtra(KEY_MEDIA_FOLDER_TYPE, type)
-        val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT)
+        val pendingIntent = PendingIntent.getActivity(
+            context,
+            0,
+            intent,
+            PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
+        )
         val notificationBuilder = NotificationCompat.Builder(
             context,
             NotificationUtils.NOTIFICATION_CHANNEL_GENERAL
@@ -214,7 +220,7 @@ class MediaFoldersDetectionWork constructor(
             context,
             notificationId,
             disableDetection,
-            PendingIntent.FLAG_CANCEL_CURRENT
+            PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
         )
         notificationBuilder.addAction(
             NotificationCompat.Action(
@@ -227,7 +233,7 @@ class MediaFoldersDetectionWork constructor(
             context,
             notificationId,
             intent,
-            PendingIntent.FLAG_CANCEL_CURRENT
+            PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
         )
         notificationBuilder.addAction(
             NotificationCompat.Action(

+ 3 - 3
src/main/java/com/nextcloud/client/jobs/NotificationWork.kt

@@ -159,7 +159,7 @@ class NotificationWork constructor(
                 context,
                 notification.getNotificationId(),
                 intent,
-                PendingIntent.FLAG_ONE_SHOT
+                PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
             )
         }
 
@@ -186,7 +186,7 @@ class NotificationWork constructor(
                 context,
                 pushNotificationId,
                 disableDetection,
-                PendingIntent.FLAG_CANCEL_CURRENT
+                PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
             )
             notificationBuilder.addAction(
                 NotificationCompat.Action(
@@ -207,7 +207,7 @@ class NotificationWork constructor(
                     context,
                     randomId.nextInt(),
                     actionIntent,
-                    PendingIntent.FLAG_CANCEL_CURRENT
+                    PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
                 )
                 var icon: Int
                 icon = if (action.primary) {

+ 2 - 2
src/main/java/com/nextcloud/client/media/PlayerService.kt

@@ -102,12 +102,12 @@ class PlayerService : Service() {
 
         val stop = Intent(this, PlayerService::class.java)
         stop.action = ACTION_STOP
-        val pendingStop = PendingIntent.getService(this, 0, stop, 0)
+        val pendingStop = PendingIntent.getService(this, 0, stop, PendingIntent.FLAG_IMMUTABLE)
         notificationBuilder.addAction(0, getString(R.string.player_stop).toUpperCase(Locale.getDefault()), pendingStop)
 
         val toggle = Intent(this, PlayerService::class.java)
         toggle.action = ACTION_TOGGLE
-        val pendingToggle = PendingIntent.getService(this, 0, toggle, 0)
+        val pendingToggle = PendingIntent.getService(this, 0, toggle, PendingIntent.FLAG_IMMUTABLE)
         notificationBuilder.addAction(
             0,
             getString(R.string.player_toggle).toUpperCase(Locale.getDefault()),

+ 1 - 1
src/main/java/com/nextcloud/client/notifications/AppNotificationManagerImpl.kt

@@ -75,7 +75,7 @@ class AppNotificationManagerImpl @Inject constructor(
                 context,
                 System.currentTimeMillis().toInt(),
                 openFileIntent,
-                0
+                PendingIntent.FLAG_IMMUTABLE
             )
             builder.setContentIntent(pendingOpenFileIntent)
         }

+ 3 - 3
src/main/java/com/owncloud/android/files/services/FileUploader.java

@@ -723,7 +723,7 @@ public class FileUploader extends Service
         mNotificationBuilder.setContentIntent(PendingIntent.getActivity(this,
                                                                         (int) System.currentTimeMillis(),
                                                                         intent,
-                                                                        0)
+                                                                        PendingIntent.FLAG_IMMUTABLE)
                                              );
 
         if (!upload.isInstantPicture() && !upload.isInstantVideo()) {
@@ -823,7 +823,7 @@ public class FileUploader extends Service
                     this,
                     (int) System.currentTimeMillis(),
                     updateAccountCredentials,
-                    PendingIntent.FLAG_ONE_SHOT
+                    PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE
                 ));
             } else {
                 Intent intent;
@@ -843,7 +843,7 @@ public class FileUploader extends Service
                 mNotificationBuilder.setContentIntent(PendingIntent.getActivity(this,
                                                                                 (int) System.currentTimeMillis(),
                                                                                 intent,
-                                                                                0)
+                                                                                PendingIntent.FLAG_IMMUTABLE)
                                                      );
             }
 

+ 1 - 1
src/main/java/com/owncloud/android/syncadapter/FileSyncAdapter.java

@@ -406,7 +406,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
                 .setContentTitle(i18n(R.string.sync_fail_ticker_unauthorized))
                 .setContentIntent(PendingIntent.getActivity(
                     getContext(), (int)System.currentTimeMillis(), updateAccountCredentials,
-                        PendingIntent.FLAG_ONE_SHOT
+                        PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE
                 ))
                 .setContentText(i18n(R.string.sync_fail_content_unauthorized, getAccount().name));
         } else {