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() {
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);
}
}

View File

@@ -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,

View File

@@ -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) {

View File

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