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
This commit is contained in:
Michael Bestas
2021-10-11 19:25:57 +03:00
parent 772843f3ce
commit aed99e306c
4 changed files with 15 additions and 11 deletions

View File

@@ -211,6 +211,7 @@ public class ExportUpdateService extends Service {
private PendingIntent getStopPendingIntent() { private PendingIntent getStopPendingIntent() {
final Intent intent = new Intent(this, ExportUpdateService.class); final Intent intent = new Intent(this, ExportUpdateService.class);
intent.setAction(ACTION_STOP_EXPORTING); 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);
} }
} }

View File

@@ -65,7 +65,7 @@ public class UpdaterReceiver extends BroadcastReceiver {
Intent notificationIntent = new Intent(context, UpdatesActivity.class); Intent notificationIntent = new Intent(context, UpdatesActivity.class);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
NotificationChannel notificationChannel = new NotificationChannel( NotificationChannel notificationChannel = new NotificationChannel(
INSTALL_ERROR_NOTIFICATION_CHANNEL, INSTALL_ERROR_NOTIFICATION_CHANNEL,

View File

@@ -134,7 +134,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
notificationBuilder.setSmallIcon(R.drawable.ic_system_update); notificationBuilder.setSmallIcon(R.drawable.ic_system_update);
Intent notificationIntent = new Intent(context, UpdatesActivity.class); Intent notificationIntent = new Intent(context, UpdatesActivity.class);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
notificationBuilder.setContentIntent(intent); notificationBuilder.setContentIntent(intent);
notificationBuilder.setContentTitle(context.getString(R.string.new_updates_found_title)); notificationBuilder.setContentTitle(context.getString(R.string.new_updates_found_title));
notificationBuilder.setAutoCancel(true); notificationBuilder.setAutoCancel(true);
@@ -145,7 +145,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
private static PendingIntent getRepeatingUpdatesCheckIntent(Context context) { private static PendingIntent getRepeatingUpdatesCheckIntent(Context context) {
Intent intent = new Intent(context, UpdatesCheckReceiver.class); Intent intent = new Intent(context, UpdatesCheckReceiver.class);
intent.setAction(DAILY_CHECK_ACTION); 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) { public static void updateRepeatingUpdatesCheck(Context context) {
@@ -177,7 +177,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
private static PendingIntent getUpdatesCheckIntent(Context context) { private static PendingIntent getUpdatesCheckIntent(Context context) {
Intent intent = new Intent(context, UpdatesCheckReceiver.class); Intent intent = new Intent(context, UpdatesCheckReceiver.class);
intent.setAction(ONESHOT_CHECK_ACTION); 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) { public static void scheduleUpdatesCheck(Context context) {

View File

@@ -100,7 +100,7 @@ public class UpdaterService extends Service {
Intent notificationIntent = new Intent(this, UpdatesActivity.class); Intent notificationIntent = new Intent(this, UpdatesActivity.class);
PendingIntent intent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent intent = PendingIntent.getActivity(this, 0, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
mNotificationBuilder.setContentIntent(intent); mNotificationBuilder.setContentIntent(intent);
mBroadcastReceiver = new BroadcastReceiver() { mBroadcastReceiver = new BroadcastReceiver() {
@@ -502,7 +502,8 @@ public class UpdaterService extends Service {
intent.setAction(ACTION_DOWNLOAD_CONTROL); intent.setAction(ACTION_DOWNLOAD_CONTROL);
intent.putExtra(EXTRA_DOWNLOAD_ID, downloadId); intent.putExtra(EXTRA_DOWNLOAD_ID, downloadId);
intent.putExtra(EXTRA_DOWNLOAD_CONTROL, DOWNLOAD_RESUME); 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) { private PendingIntent getPausePendingIntent(String downloadId) {
@@ -510,26 +511,28 @@ public class UpdaterService extends Service {
intent.setAction(ACTION_DOWNLOAD_CONTROL); intent.setAction(ACTION_DOWNLOAD_CONTROL);
intent.putExtra(EXTRA_DOWNLOAD_ID, downloadId); intent.putExtra(EXTRA_DOWNLOAD_ID, downloadId);
intent.putExtra(EXTRA_DOWNLOAD_CONTROL, DOWNLOAD_PAUSE); 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() { private PendingIntent getRebootPendingIntent() {
final Intent intent = new Intent(this, UpdaterReceiver.class); final Intent intent = new Intent(this, UpdaterReceiver.class);
intent.setAction(UpdaterReceiver.ACTION_INSTALL_REBOOT); 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() { private PendingIntent getSuspendInstallationPendingIntent() {
final Intent intent = new Intent(this, UpdaterService.class); final Intent intent = new Intent(this, UpdaterService.class);
intent.setAction(ACTION_INSTALL_SUSPEND); intent.setAction(ACTION_INSTALL_SUSPEND);
return PendingIntent.getService(this, 0, intent, return PendingIntent.getService(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
} }
private PendingIntent getResumeInstallationPendingIntent() { private PendingIntent getResumeInstallationPendingIntent() {
final Intent intent = new Intent(this, UpdaterService.class); final Intent intent = new Intent(this, UpdaterService.class);
intent.setAction(ACTION_INSTALL_RESUME); intent.setAction(ACTION_INSTALL_RESUME);
return PendingIntent.getService(this, 0, intent, return PendingIntent.getService(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
} }
} }