Browse Source

Merge pull request #9726 from nextcloud/fix/immutable-intents

Make PendingIntents immutable
Álvaro Brey 3 years ago
parent
commit
4a29c2e4c4

+ 1 - 1
scripts/analysis/findbugs-results.txt

@@ -1 +1 @@
-642
+641

+ 1 - 1
scripts/analysis/lint-results.txt

@@ -1,2 +1,2 @@
 DO NOT TOUCH; GENERATED BY DRONE
-      <span class="mdl-layout-title">Lint Report: 124 warnings</span>
+      <span class="mdl-layout-title">Lint Report: 102 warnings</span>

+ 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)
         }

+ 8 - 4
src/main/java/com/owncloud/android/files/services/FileDownloader.java

@@ -579,7 +579,7 @@ public class FileDownloader extends Service
         showDetailsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 
         mNotificationBuilder.setContentIntent(PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
-                showDetailsIntent, 0));
+                                                                        showDetailsIntent, PendingIntent.FLAG_IMMUTABLE));
 
 
         if (mNotificationManager == null) {
@@ -659,7 +659,7 @@ public class FileDownloader extends Service
                 // TODO put something smart in showDetailsIntent
                 Intent showDetailsIntent = new Intent();
                 mNotificationBuilder.setContentIntent(PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
-                        showDetailsIntent, 0));
+                                                                                showDetailsIntent, PendingIntent.FLAG_IMMUTABLE));
             }
 
             mNotificationBuilder.setContentText(ErrorMessageAdapter.getErrorCauseMessage(downloadResult,
@@ -689,8 +689,12 @@ public class FileDownloader extends Service
         updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
         updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND);
-        mNotificationBuilder.setContentIntent(PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
-                updateAccountCredentials, PendingIntent.FLAG_ONE_SHOT));
+        mNotificationBuilder.setContentIntent(
+            PendingIntent.getActivity(this,
+                                      (int) System.currentTimeMillis(),
+                                      updateAccountCredentials,
+                                      PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE)
+                                             );
     }
 
 

+ 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)
                                                      );
             }
 

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

@@ -34,9 +34,7 @@ import android.content.Intent;
 import android.content.SyncResult;
 import android.os.Bundle;
 
-import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.UserAccountManager;
-import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.authentication.AuthenticatorActivity;
 import com.owncloud.android.datamodel.FileDataStorageManager;
@@ -408,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 {
@@ -436,8 +434,8 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
             // TODO put something smart in the contentIntent below
             notificationBuilder
                 .setContentIntent(PendingIntent.getActivity(
-                    getContext(), (int) System.currentTimeMillis(), new Intent(), 0
-                ))
+                    getContext(), (int) System.currentTimeMillis(), new Intent(), PendingIntent.FLAG_IMMUTABLE
+                                                           ))
                 .setContentTitle(i18n(R.string.sync_fail_in_favourites_ticker))
                 .setContentText(getQuantityString(
                     R.plurals.sync_fail_in_favourites_content,
@@ -454,8 +452,8 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
             // TODO put something smart in the contentIntent below
             notificationBuilder
                 .setContentIntent(PendingIntent.getActivity(
-                    getContext(), (int) System.currentTimeMillis(), new Intent(), 0
-                ))
+                    getContext(), (int) System.currentTimeMillis(), new Intent(), PendingIntent.FLAG_IMMUTABLE
+                                                           ))
                 .setContentTitle(i18n(R.string.sync_conflicts_in_favourites_ticker))
                 .setContentText(i18n(R.string.sync_conflicts_in_favourites_ticker, mConflictsFound));
 
@@ -491,8 +489,8 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
 
         notificationBuilder
             .setContentIntent(PendingIntent.getActivity(
-                getContext(), (int) System.currentTimeMillis(), explanationIntent, 0
-            ))
+                getContext(), (int) System.currentTimeMillis(), explanationIntent, PendingIntent.FLAG_IMMUTABLE
+                                                       ))
             .setContentTitle(i18n(R.string.sync_foreign_files_forgotten_ticker))
             .setContentText(getQuantityString(
                     R.plurals.sync_foreign_files_forgotten_content,