From aed99e306c8ca3a356fb658cffc88a15a92db7e8 Mon Sep 17 00:00:00 2001 From: Michael Bestas Date: Mon, 11 Oct 2021 19:25:57 +0300 Subject: [PATCH] Updater: Add FLAG_IMMUTABLE flag to PendingIntent Fixes: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles. Change-Id: I63b25512d3bf6e0d3b0cc95d91295f4065175848 --- .../lineageos/updater/ExportUpdateService.java | 3 ++- src/org/lineageos/updater/UpdaterReceiver.java | 2 +- .../lineageos/updater/UpdatesCheckReceiver.java | 6 +++--- .../updater/controller/UpdaterService.java | 15 +++++++++------ 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/org/lineageos/updater/ExportUpdateService.java b/src/org/lineageos/updater/ExportUpdateService.java index 2406d2f..9d60716 100644 --- a/src/org/lineageos/updater/ExportUpdateService.java +++ b/src/org/lineageos/updater/ExportUpdateService.java @@ -211,6 +211,7 @@ public class ExportUpdateService extends Service { private PendingIntent getStopPendingIntent() { final Intent intent = new Intent(this, ExportUpdateService.class); intent.setAction(ACTION_STOP_EXPORTING); - return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + return PendingIntent.getService(this, 0, intent, + PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); } } diff --git a/src/org/lineageos/updater/UpdaterReceiver.java b/src/org/lineageos/updater/UpdaterReceiver.java index 51b87d0..fa0f6df 100644 --- a/src/org/lineageos/updater/UpdaterReceiver.java +++ b/src/org/lineageos/updater/UpdaterReceiver.java @@ -65,7 +65,7 @@ public class UpdaterReceiver extends BroadcastReceiver { Intent notificationIntent = new Intent(context, UpdatesActivity.class); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, - PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); NotificationChannel notificationChannel = new NotificationChannel( INSTALL_ERROR_NOTIFICATION_CHANNEL, diff --git a/src/org/lineageos/updater/UpdatesCheckReceiver.java b/src/org/lineageos/updater/UpdatesCheckReceiver.java index 288cd1a..5f8c69d 100644 --- a/src/org/lineageos/updater/UpdatesCheckReceiver.java +++ b/src/org/lineageos/updater/UpdatesCheckReceiver.java @@ -134,7 +134,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { notificationBuilder.setSmallIcon(R.drawable.ic_system_update); Intent notificationIntent = new Intent(context, UpdatesActivity.class); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, - PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); notificationBuilder.setContentIntent(intent); notificationBuilder.setContentTitle(context.getString(R.string.new_updates_found_title)); notificationBuilder.setAutoCancel(true); @@ -145,7 +145,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { private static PendingIntent getRepeatingUpdatesCheckIntent(Context context) { Intent intent = new Intent(context, UpdatesCheckReceiver.class); intent.setAction(DAILY_CHECK_ACTION); - return PendingIntent.getBroadcast(context, 0, intent, 0); + return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_IMMUTABLE); } public static void updateRepeatingUpdatesCheck(Context context) { @@ -177,7 +177,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { private static PendingIntent getUpdatesCheckIntent(Context context) { Intent intent = new Intent(context, UpdatesCheckReceiver.class); intent.setAction(ONESHOT_CHECK_ACTION); - return PendingIntent.getBroadcast(context, 0, intent, 0); + return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_IMMUTABLE); } public static void scheduleUpdatesCheck(Context context) { diff --git a/src/org/lineageos/updater/controller/UpdaterService.java b/src/org/lineageos/updater/controller/UpdaterService.java index 3371618..9d60ef4 100644 --- a/src/org/lineageos/updater/controller/UpdaterService.java +++ b/src/org/lineageos/updater/controller/UpdaterService.java @@ -100,7 +100,7 @@ public class UpdaterService extends Service { Intent notificationIntent = new Intent(this, UpdatesActivity.class); PendingIntent intent = PendingIntent.getActivity(this, 0, notificationIntent, - PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); mNotificationBuilder.setContentIntent(intent); mBroadcastReceiver = new BroadcastReceiver() { @@ -502,7 +502,8 @@ public class UpdaterService extends Service { intent.setAction(ACTION_DOWNLOAD_CONTROL); intent.putExtra(EXTRA_DOWNLOAD_ID, downloadId); intent.putExtra(EXTRA_DOWNLOAD_CONTROL, DOWNLOAD_RESUME); - return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + return PendingIntent.getService(this, 0, intent, + PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); } private PendingIntent getPausePendingIntent(String downloadId) { @@ -510,26 +511,28 @@ public class UpdaterService extends Service { intent.setAction(ACTION_DOWNLOAD_CONTROL); intent.putExtra(EXTRA_DOWNLOAD_ID, downloadId); intent.putExtra(EXTRA_DOWNLOAD_CONTROL, DOWNLOAD_PAUSE); - return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + return PendingIntent.getService(this, 0, intent, + PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); } private PendingIntent getRebootPendingIntent() { final Intent intent = new Intent(this, UpdaterReceiver.class); intent.setAction(UpdaterReceiver.ACTION_INSTALL_REBOOT); - return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + return PendingIntent.getBroadcast(this, 0, intent, + PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); } private PendingIntent getSuspendInstallationPendingIntent() { final Intent intent = new Intent(this, UpdaterService.class); intent.setAction(ACTION_INSTALL_SUSPEND); return PendingIntent.getService(this, 0, intent, - PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); } private PendingIntent getResumeInstallationPendingIntent() { final Intent intent = new Intent(this, UpdaterService.class); intent.setAction(ACTION_INSTALL_RESUME); return PendingIntent.getService(this, 0, intent, - PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); } }