Add appropriate mutability flags to PendingIntents
This commit is contained in:
parent
e61666db81
commit
8847e30cb7
6 changed files with 51 additions and 28 deletions
|
@ -0,0 +1,12 @@
|
|||
package com.fsck.k9.helper
|
||||
|
||||
import android.app.PendingIntent
|
||||
import android.os.Build
|
||||
|
||||
object PendingIntentCompat {
|
||||
@JvmField
|
||||
val FLAG_IMMUTABLE = if (Build.VERSION.SDK_INT >= 23) PendingIntent.FLAG_IMMUTABLE else 0
|
||||
|
||||
@JvmField
|
||||
val FLAG_MUTABLE = if (Build.VERSION.SDK_INT >= 31) PendingIntent.FLAG_MUTABLE else 0
|
||||
}
|
|
@ -4,10 +4,10 @@ import android.app.Notification
|
|||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import com.fsck.k9.CoreResourceProvider
|
||||
import com.fsck.k9.helper.PendingIntentCompat.FLAG_IMMUTABLE
|
||||
|
||||
private const val PUSH_INFO_ACTION = "app.k9mail.action.PUSH_INFO"
|
||||
|
||||
|
@ -54,8 +54,7 @@ internal class PushNotificationManager(
|
|||
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||
setPackage(context.packageName)
|
||||
}
|
||||
val flag = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0
|
||||
val contentIntent = PendingIntent.getActivity(context, 1, intent, flag)
|
||||
val contentIntent = PendingIntent.getActivity(context, 1, intent, FLAG_IMMUTABLE)
|
||||
|
||||
return NotificationCompat.Builder(context, notificationChannelManager.pushChannelId)
|
||||
.setSmallIcon(resourceProvider.iconPushNotification)
|
||||
|
|
|
@ -5,10 +5,10 @@ import android.content.BroadcastReceiver
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.os.Build
|
||||
import android.os.SystemClock
|
||||
import com.fsck.k9.backend.imap.SystemAlarmManager
|
||||
import com.fsck.k9.helper.AlarmManagerCompat
|
||||
import com.fsck.k9.helper.PendingIntentCompat.FLAG_IMMUTABLE
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
@ -32,9 +32,8 @@ class AndroidAlarmManager(
|
|||
val intent = Intent(ALARM_ACTION).apply {
|
||||
setPackage(context.packageName)
|
||||
}
|
||||
val flags = if (Build.VERSION.SDK_INT >= 23) PendingIntent.FLAG_IMMUTABLE else 0
|
||||
|
||||
PendingIntent.getBroadcast(context, REQUEST_CODE, intent, flags)
|
||||
PendingIntent.getBroadcast(context, REQUEST_CODE, intent, FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
private val callback = AtomicReference<Callback?>(null)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.fsck.k9.notification
|
||||
|
||||
import android.app.PendingIntent
|
||||
import android.app.PendingIntent.FLAG_CANCEL_CURRENT
|
||||
import android.app.PendingIntent.FLAG_UPDATE_CURRENT
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.fsck.k9.Account
|
||||
|
@ -10,6 +12,7 @@ import com.fsck.k9.activity.compose.MessageActions
|
|||
import com.fsck.k9.activity.setup.AccountSetupIncoming
|
||||
import com.fsck.k9.activity.setup.AccountSetupOutgoing
|
||||
import com.fsck.k9.controller.MessageReference
|
||||
import com.fsck.k9.helper.PendingIntentCompat.FLAG_IMMUTABLE
|
||||
import com.fsck.k9.mailstore.MessageStoreManager
|
||||
import com.fsck.k9.search.LocalSearch
|
||||
import com.fsck.k9.ui.messagelist.DefaultFolderProvider
|
||||
|
@ -38,12 +41,12 @@ internal class K9NotificationActionCreator(
|
|||
val openInUnifiedInbox = K9.isShowUnifiedInbox && isIncludedInUnifiedInbox(messageReference)
|
||||
val intent = createMessageViewIntent(messageReference, openInUnifiedInbox)
|
||||
|
||||
return PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getActivity(context, notificationId, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
override fun createViewFolderPendingIntent(account: Account, folderId: Long, notificationId: Int): PendingIntent {
|
||||
val intent = createMessageListIntent(account, folderId)
|
||||
return PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getActivity(context, notificationId, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
override fun createViewMessagesPendingIntent(
|
||||
|
@ -61,17 +64,17 @@ internal class K9NotificationActionCreator(
|
|||
createNewMessagesIntent(account)
|
||||
}
|
||||
|
||||
return PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getActivity(context, notificationId, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
override fun createViewFolderListPendingIntent(account: Account, notificationId: Int): PendingIntent {
|
||||
val intent = createMessageListIntent(account)
|
||||
return PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getActivity(context, notificationId, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
override fun createDismissAllMessagesPendingIntent(account: Account, notificationId: Int): PendingIntent {
|
||||
val intent = NotificationActionService.createDismissAllMessagesIntent(context, account)
|
||||
return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getService(context, notificationId, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
override fun createDismissMessagePendingIntent(
|
||||
|
@ -79,12 +82,12 @@ internal class K9NotificationActionCreator(
|
|||
notificationId: Int
|
||||
): PendingIntent {
|
||||
val intent = NotificationActionService.createDismissMessageIntent(context, messageReference)
|
||||
return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getService(context, notificationId, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
override fun createReplyPendingIntent(messageReference: MessageReference, notificationId: Int): PendingIntent {
|
||||
val intent = MessageActions.getActionReplyIntent(context, messageReference)
|
||||
return PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getActivity(context, notificationId, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
override fun createMarkMessageAsReadPendingIntent(
|
||||
|
@ -92,7 +95,7 @@ internal class K9NotificationActionCreator(
|
|||
notificationId: Int
|
||||
): PendingIntent {
|
||||
val intent = NotificationActionService.createMarkMessageAsReadIntent(context, messageReference)
|
||||
return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getService(context, notificationId, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
override fun createMarkAllAsReadPendingIntent(
|
||||
|
@ -102,17 +105,17 @@ internal class K9NotificationActionCreator(
|
|||
): PendingIntent {
|
||||
val accountUuid = account.uuid
|
||||
val intent = NotificationActionService.createMarkAllAsReadIntent(context, accountUuid, messageReferences)
|
||||
return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getService(context, notificationId, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
override fun getEditIncomingServerSettingsIntent(account: Account): PendingIntent {
|
||||
val intent = AccountSetupIncoming.intentActionEditIncomingSettings(context, account)
|
||||
return PendingIntent.getActivity(context, account.accountNumber, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getActivity(context, account.accountNumber, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
override fun getEditOutgoingServerSettingsIntent(account: Account): PendingIntent {
|
||||
val intent = AccountSetupOutgoing.intentActionEditOutgoingSettings(context, account)
|
||||
return PendingIntent.getActivity(context, account.accountNumber, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getActivity(context, account.accountNumber, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
override fun createDeleteMessagePendingIntent(
|
||||
|
@ -131,7 +134,7 @@ internal class K9NotificationActionCreator(
|
|||
notificationId: Int
|
||||
): PendingIntent {
|
||||
val intent = NotificationActionService.createDeleteMessageIntent(context, messageReference)
|
||||
return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getService(context, notificationId, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
private fun createDeleteConfirmationPendingIntent(
|
||||
|
@ -139,7 +142,7 @@ internal class K9NotificationActionCreator(
|
|||
notificationId: Int
|
||||
): PendingIntent {
|
||||
val intent = DeleteConfirmationActivity.getIntent(context, messageReference)
|
||||
return PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getActivity(context, notificationId, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
override fun createDeleteAllPendingIntent(
|
||||
|
@ -159,7 +162,7 @@ internal class K9NotificationActionCreator(
|
|||
notificationId: Int
|
||||
): PendingIntent {
|
||||
val intent = DeleteConfirmationActivity.getIntent(context, messageReferences)
|
||||
return PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_CANCEL_CURRENT)
|
||||
return PendingIntent.getActivity(context, notificationId, intent, FLAG_CANCEL_CURRENT or FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
private fun getDeleteAllServicePendingIntent(
|
||||
|
@ -169,7 +172,7 @@ internal class K9NotificationActionCreator(
|
|||
): PendingIntent {
|
||||
val accountUuid = account.uuid
|
||||
val intent = NotificationActionService.createDeleteAllMessagesIntent(context, accountUuid, messageReferences)
|
||||
return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getService(context, notificationId, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
override fun createArchiveMessagePendingIntent(
|
||||
|
@ -177,7 +180,7 @@ internal class K9NotificationActionCreator(
|
|||
notificationId: Int
|
||||
): PendingIntent {
|
||||
val intent = NotificationActionService.createArchiveMessageIntent(context, messageReference)
|
||||
return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getService(context, notificationId, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
override fun createArchiveAllPendingIntent(
|
||||
|
@ -186,7 +189,7 @@ internal class K9NotificationActionCreator(
|
|||
notificationId: Int
|
||||
): PendingIntent {
|
||||
val intent = NotificationActionService.createArchiveAllIntent(context, account, messageReferences)
|
||||
return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getService(context, notificationId, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
override fun createMarkMessageAsSpamPendingIntent(
|
||||
|
@ -194,7 +197,7 @@ internal class K9NotificationActionCreator(
|
|||
notificationId: Int
|
||||
): PendingIntent {
|
||||
val intent = NotificationActionService.createMarkMessageAsSpamIntent(context, messageReference)
|
||||
return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getService(context, notificationId, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
private fun createMessageListIntent(account: Account): Intent {
|
||||
|
|
|
@ -10,6 +10,7 @@ import android.view.View
|
|||
import android.widget.RemoteViews
|
||||
import com.fsck.k9.EarlyInit
|
||||
import com.fsck.k9.R
|
||||
import com.fsck.k9.helper.PendingIntentCompat.FLAG_MUTABLE
|
||||
import com.fsck.k9.inject
|
||||
import com.fsck.k9.widget.unread.UnreadWidgetConfigurationActivity
|
||||
import com.fsck.k9.widget.unread.UnreadWidgetData
|
||||
|
@ -85,7 +86,12 @@ class UnreadWidgetProvider : AppWidgetProvider(), EarlyInit {
|
|||
}
|
||||
clickIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
|
||||
val pendingIntent = PendingIntent.getActivity(context, appWidgetId, clickIntent, FLAG_UPDATE_CURRENT)
|
||||
val pendingIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
appWidgetId,
|
||||
clickIntent,
|
||||
FLAG_UPDATE_CURRENT or FLAG_MUTABLE
|
||||
)
|
||||
remoteViews.setOnClickPendingIntent(R.id.unread_widget_layout, pendingIntent)
|
||||
|
||||
appWidgetManager.updateAppWidget(appWidgetId, remoteViews)
|
||||
|
|
|
@ -15,6 +15,10 @@ import com.fsck.k9.activity.MessageCompose;
|
|||
import com.fsck.k9.activity.MessageList;
|
||||
import com.fsck.k9.search.SearchAccount;
|
||||
|
||||
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
|
||||
import static com.fsck.k9.helper.PendingIntentCompat.FLAG_IMMUTABLE;
|
||||
import static com.fsck.k9.helper.PendingIntentCompat.FLAG_MUTABLE;
|
||||
|
||||
|
||||
public class MessageListWidgetProvider extends AppWidgetProvider {
|
||||
private static final String ACTION_UPDATE_MESSAGE_LIST = "UPDATE_MESSAGE_LIST";
|
||||
|
@ -77,7 +81,7 @@ public class MessageListWidgetProvider extends AppWidgetProvider {
|
|||
Intent intent = new Intent(context, MessageList.class);
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
|
||||
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
return PendingIntent.getActivity(context, 0, intent, FLAG_UPDATE_CURRENT | FLAG_MUTABLE);
|
||||
}
|
||||
|
||||
private PendingIntent viewUnifiedInboxPendingIntent(Context context) {
|
||||
|
@ -85,13 +89,13 @@ public class MessageListWidgetProvider extends AppWidgetProvider {
|
|||
Intent intent = MessageList.intentDisplaySearch(
|
||||
context, unifiedInboxAccount.getRelatedSearch(), true, true, true);
|
||||
|
||||
return PendingIntent.getActivity(context, -1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
return PendingIntent.getActivity(context, -1, intent, FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE);
|
||||
}
|
||||
|
||||
private PendingIntent composeActionPendingIntent(Context context) {
|
||||
Intent intent = new Intent(context, MessageCompose.class);
|
||||
intent.setAction(MessageCompose.ACTION_COMPOSE);
|
||||
|
||||
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
return PendingIntent.getActivity(context, 0, intent, FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue