mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-26 06:11:19 +00:00
Set FLAG_IMMUTABLE on PendingIntent (target 31) (#1868)
Co-authored-by: Catfriend1 <16361913+Catfriend1@users.noreply.github.com>
This commit is contained in:
parent
9bd413705c
commit
b89c9833eb
3 changed files with 13 additions and 9 deletions
|
@ -1,6 +1,7 @@
|
||||||
package com.nutomic.syncthingandroid.service;
|
package com.nutomic.syncthingandroid.service;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
|
import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
@ -143,4 +144,6 @@ public class Constants {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int FLAG_IMMUTABLE = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) ? PendingIntent.FLAG_IMMUTABLE : 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -239,7 +239,7 @@ public class EventProcessor implements Runnable, RestApi.OnReceiveEventListener
|
||||||
.putExtra(DeviceActivity.EXTRA_DEVICE_ID, deviceId)
|
.putExtra(DeviceActivity.EXTRA_DEVICE_ID, deviceId)
|
||||||
.putExtra(DeviceActivity.EXTRA_DEVICE_NAME, deviceName);
|
.putExtra(DeviceActivity.EXTRA_DEVICE_NAME, deviceName);
|
||||||
PendingIntent piAccept = PendingIntent.getActivity(mContext, notificationId,
|
PendingIntent piAccept = PendingIntent.getActivity(mContext, notificationId,
|
||||||
intentAccept, PendingIntent.FLAG_UPDATE_CURRENT);
|
intentAccept, Constants.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
// Prepare "ignore" action.
|
// Prepare "ignore" action.
|
||||||
Intent intentIgnore = new Intent(mContext, SyncthingService.class)
|
Intent intentIgnore = new Intent(mContext, SyncthingService.class)
|
||||||
|
@ -249,7 +249,7 @@ public class EventProcessor implements Runnable, RestApi.OnReceiveEventListener
|
||||||
.putExtra(SyncthingService.EXTRA_DEVICE_ADDRESS, deviceAddress);
|
.putExtra(SyncthingService.EXTRA_DEVICE_ADDRESS, deviceAddress);
|
||||||
intentIgnore.setAction(SyncthingService.ACTION_IGNORE_DEVICE);
|
intentIgnore.setAction(SyncthingService.ACTION_IGNORE_DEVICE);
|
||||||
PendingIntent piIgnore = PendingIntent.getService(mContext, 0,
|
PendingIntent piIgnore = PendingIntent.getService(mContext, 0,
|
||||||
intentIgnore, PendingIntent.FLAG_UPDATE_CURRENT);
|
intentIgnore, Constants.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
// Show notification.
|
// Show notification.
|
||||||
mNotificationHandler.showConsentNotification(notificationId, title, piAccept, piIgnore);
|
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_ID, folderId)
|
||||||
.putExtra(FolderActivity.EXTRA_FOLDER_LABEL, folderLabel);
|
.putExtra(FolderActivity.EXTRA_FOLDER_LABEL, folderLabel);
|
||||||
PendingIntent piAccept = PendingIntent.getActivity(mContext, notificationId,
|
PendingIntent piAccept = PendingIntent.getActivity(mContext, notificationId,
|
||||||
intentAccept, PendingIntent.FLAG_UPDATE_CURRENT);
|
intentAccept, Constants.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
// Prepare "ignore" action.
|
// Prepare "ignore" action.
|
||||||
Intent intentIgnore = new Intent(mContext, SyncthingService.class)
|
Intent intentIgnore = new Intent(mContext, SyncthingService.class)
|
||||||
|
@ -297,7 +297,7 @@ public class EventProcessor implements Runnable, RestApi.OnReceiveEventListener
|
||||||
.putExtra(SyncthingService.EXTRA_FOLDER_LABEL, folderLabel);
|
.putExtra(SyncthingService.EXTRA_FOLDER_LABEL, folderLabel);
|
||||||
intentIgnore.setAction(SyncthingService.ACTION_IGNORE_FOLDER);
|
intentIgnore.setAction(SyncthingService.ACTION_IGNORE_FOLDER);
|
||||||
PendingIntent piIgnore = PendingIntent.getService(mContext, 0,
|
PendingIntent piIgnore = PendingIntent.getService(mContext, 0,
|
||||||
intentIgnore, PendingIntent.FLAG_UPDATE_CURRENT);
|
intentIgnore, Constants.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
// Show notification.
|
// Show notification.
|
||||||
mNotificationHandler.showConsentNotification(notificationId, title, piAccept, piIgnore);
|
mNotificationHandler.showConsentNotification(notificationId, title, piAccept, piIgnore);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.nutomic.syncthingandroid.service;
|
package com.nutomic.syncthingandroid.service;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
|
@ -165,7 +166,7 @@ public class NotificationHandler {
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.setOnlyAlertOnce(true)
|
.setOnlyAlertOnce(true)
|
||||||
.setPriority(NotificationCompat.PRIORITY_MIN)
|
.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 (!appShutdownInProgress) {
|
||||||
if (startForegroundService) {
|
if (startForegroundService) {
|
||||||
Log.v(TAG, "Starting foreground service or updating notification");
|
Log.v(TAG, "Starting foreground service or updating notification");
|
||||||
|
@ -198,7 +199,7 @@ public class NotificationHandler {
|
||||||
.setContentTitle(mContext.getString(title))
|
.setContentTitle(mContext.getString(title))
|
||||||
.setContentText(mContext.getString(R.string.notification_crash_text))
|
.setContentText(mContext.getString(R.string.notification_crash_text))
|
||||||
.setSmallIcon(R.drawable.ic_stat_notify)
|
.setSmallIcon(R.drawable.ic_stat_notify)
|
||||||
.setContentIntent(PendingIntent.getActivity(mContext, 0, intent, 0))
|
.setContentIntent(PendingIntent.getActivity(mContext, 0, intent, Constants.FLAG_IMMUTABLE))
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.build();
|
.build();
|
||||||
mNotificationManager.notify(ID_CRASH, n);
|
mNotificationManager.notify(ID_CRASH, n);
|
||||||
|
@ -258,7 +259,7 @@ public class NotificationHandler {
|
||||||
.setContentTitle(mContext.getString(R.string.syncthing_terminated))
|
.setContentTitle(mContext.getString(R.string.syncthing_terminated))
|
||||||
.setContentText(mContext.getString(R.string.toast_write_storage_permission_required))
|
.setContentText(mContext.getString(R.string.toast_write_storage_permission_required))
|
||||||
.setSmallIcon(R.drawable.ic_stat_notify)
|
.setSmallIcon(R.drawable.ic_stat_notify)
|
||||||
.setContentIntent(PendingIntent.getActivity(mContext, 0, intent, 0))
|
.setContentIntent(PendingIntent.getActivity(mContext, 0, intent, Constants.FLAG_IMMUTABLE))
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setOnlyAlertOnce(true)
|
.setOnlyAlertOnce(true)
|
||||||
.build();
|
.build();
|
||||||
|
@ -268,7 +269,7 @@ public class NotificationHandler {
|
||||||
public void showRestartNotification() {
|
public void showRestartNotification() {
|
||||||
Intent intent = new Intent(mContext, SyncthingService.class)
|
Intent intent = new Intent(mContext, SyncthingService.class)
|
||||||
.setAction(SyncthingService.ACTION_RESTART);
|
.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)
|
Notification n = getNotificationBuilder(mInfoChannel)
|
||||||
.setContentTitle(mContext.getString(R.string.restart_title))
|
.setContentTitle(mContext.getString(R.string.restart_title))
|
||||||
|
@ -295,7 +296,7 @@ public class NotificationHandler {
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setContentIntent(PendingIntent.getActivity(mContext, 0,
|
.setContentIntent(PendingIntent.getActivity(mContext, 0,
|
||||||
new Intent(mContext, MainActivity.class),
|
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) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
|
Loading…
Reference in a new issue