Set FLAG_IMMUTABLE on PendingIntent (target 31) (#1868)

Co-authored-by: Catfriend1 <16361913+Catfriend1@users.noreply.github.com>
This commit is contained in:
Simon Frei 2022-11-27 20:24:35 +01:00 committed by GitHub
parent 9bd413705c
commit b89c9833eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 9 deletions

View File

@ -1,6 +1,7 @@
package com.nutomic.syncthingandroid.service;
import android.Manifest;
import android.app.PendingIntent;
import android.content.Context;
import android.os.Build;
import android.os.Environment;
@ -143,4 +144,6 @@ public class Constants {
return true;
}
public static int FLAG_IMMUTABLE = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) ? PendingIntent.FLAG_IMMUTABLE : 0;
}

View File

@ -239,7 +239,7 @@ public class EventProcessor implements Runnable, RestApi.OnReceiveEventListener
.putExtra(DeviceActivity.EXTRA_DEVICE_ID, deviceId)
.putExtra(DeviceActivity.EXTRA_DEVICE_NAME, deviceName);
PendingIntent piAccept = PendingIntent.getActivity(mContext, notificationId,
intentAccept, PendingIntent.FLAG_UPDATE_CURRENT);
intentAccept, Constants.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
// Prepare "ignore" action.
Intent intentIgnore = new Intent(mContext, SyncthingService.class)
@ -249,7 +249,7 @@ public class EventProcessor implements Runnable, RestApi.OnReceiveEventListener
.putExtra(SyncthingService.EXTRA_DEVICE_ADDRESS, deviceAddress);
intentIgnore.setAction(SyncthingService.ACTION_IGNORE_DEVICE);
PendingIntent piIgnore = PendingIntent.getService(mContext, 0,
intentIgnore, PendingIntent.FLAG_UPDATE_CURRENT);
intentIgnore, Constants.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
// Show notification.
mNotificationHandler.showConsentNotification(notificationId, title, piAccept, piIgnore);
@ -287,7 +287,7 @@ public class EventProcessor implements Runnable, RestApi.OnReceiveEventListener
.putExtra(FolderActivity.EXTRA_FOLDER_ID, folderId)
.putExtra(FolderActivity.EXTRA_FOLDER_LABEL, folderLabel);
PendingIntent piAccept = PendingIntent.getActivity(mContext, notificationId,
intentAccept, PendingIntent.FLAG_UPDATE_CURRENT);
intentAccept, Constants.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
// Prepare "ignore" action.
Intent intentIgnore = new Intent(mContext, SyncthingService.class)
@ -297,7 +297,7 @@ public class EventProcessor implements Runnable, RestApi.OnReceiveEventListener
.putExtra(SyncthingService.EXTRA_FOLDER_LABEL, folderLabel);
intentIgnore.setAction(SyncthingService.ACTION_IGNORE_FOLDER);
PendingIntent piIgnore = PendingIntent.getService(mContext, 0,
intentIgnore, PendingIntent.FLAG_UPDATE_CURRENT);
intentIgnore, Constants.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
// Show notification.
mNotificationHandler.showConsentNotification(notificationId, title, piAccept, piIgnore);

View File

@ -1,5 +1,6 @@
package com.nutomic.syncthingandroid.service;
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
@ -165,7 +166,7 @@ public class NotificationHandler {
.setOngoing(true)
.setOnlyAlertOnce(true)
.setPriority(NotificationCompat.PRIORITY_MIN)
.setContentIntent(PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
.setContentIntent(PendingIntent.getActivity(mContext, 0, intent, Constants.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT));
if (!appShutdownInProgress) {
if (startForegroundService) {
Log.v(TAG, "Starting foreground service or updating notification");
@ -198,7 +199,7 @@ public class NotificationHandler {
.setContentTitle(mContext.getString(title))
.setContentText(mContext.getString(R.string.notification_crash_text))
.setSmallIcon(R.drawable.ic_stat_notify)
.setContentIntent(PendingIntent.getActivity(mContext, 0, intent, 0))
.setContentIntent(PendingIntent.getActivity(mContext, 0, intent, Constants.FLAG_IMMUTABLE))
.setAutoCancel(true)
.build();
mNotificationManager.notify(ID_CRASH, n);
@ -258,7 +259,7 @@ public class NotificationHandler {
.setContentTitle(mContext.getString(R.string.syncthing_terminated))
.setContentText(mContext.getString(R.string.toast_write_storage_permission_required))
.setSmallIcon(R.drawable.ic_stat_notify)
.setContentIntent(PendingIntent.getActivity(mContext, 0, intent, 0))
.setContentIntent(PendingIntent.getActivity(mContext, 0, intent, Constants.FLAG_IMMUTABLE))
.setAutoCancel(true)
.setOnlyAlertOnce(true)
.build();
@ -268,7 +269,7 @@ public class NotificationHandler {
public void showRestartNotification() {
Intent intent = new Intent(mContext, SyncthingService.class)
.setAction(SyncthingService.ACTION_RESTART);
PendingIntent pi = PendingIntent.getService(mContext, 0, intent, 0);
PendingIntent pi = PendingIntent.getService(mContext, 0, intent, Constants.FLAG_IMMUTABLE);
Notification n = getNotificationBuilder(mInfoChannel)
.setContentTitle(mContext.getString(R.string.restart_title))
@ -295,7 +296,7 @@ public class NotificationHandler {
.setAutoCancel(true)
.setContentIntent(PendingIntent.getActivity(mContext, 0,
new Intent(mContext, MainActivity.class),
PendingIntent.FLAG_UPDATE_CURRENT));
Constants.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {