diff --git a/app/common/src/main/java/com/fsck/k9/backends/AndroidAlarmManager.kt b/app/common/src/main/java/com/fsck/k9/backends/AndroidAlarmManager.kt index bdc46e234..9e8696aa9 100644 --- a/app/common/src/main/java/com/fsck/k9/backends/AndroidAlarmManager.kt +++ b/app/common/src/main/java/com/fsck/k9/backends/AndroidAlarmManager.kt @@ -6,10 +6,10 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.os.SystemClock +import androidx.core.app.PendingIntentCompat import androidx.core.content.ContextCompat 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 @@ -34,7 +34,7 @@ class AndroidAlarmManager( setPackage(context.packageName) } - PendingIntent.getBroadcast(context, REQUEST_CODE, intent, FLAG_IMMUTABLE) + PendingIntentCompat.getBroadcast(context, REQUEST_CODE, intent, 0, false)!! } private val callback = AtomicReference(null) diff --git a/app/common/src/main/java/com/fsck/k9/notification/K9NotificationActionCreator.kt b/app/common/src/main/java/com/fsck/k9/notification/K9NotificationActionCreator.kt index f616ecd4c..7698f280e 100644 --- a/app/common/src/main/java/com/fsck/k9/notification/K9NotificationActionCreator.kt +++ b/app/common/src/main/java/com/fsck/k9/notification/K9NotificationActionCreator.kt @@ -6,13 +6,13 @@ import android.app.PendingIntent.FLAG_UPDATE_CURRENT import android.content.Context import android.content.Intent import android.net.Uri +import androidx.core.app.PendingIntentCompat import app.k9mail.feature.launcher.FeatureLauncherActivity import com.fsck.k9.Account import com.fsck.k9.K9 import com.fsck.k9.activity.MessageList import com.fsck.k9.activity.compose.MessageActions 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 @@ -40,12 +40,12 @@ internal class K9NotificationActionCreator( val openInUnifiedInbox = K9.isShowUnifiedInbox && isIncludedInUnifiedInbox(messageReference) val intent = createMessageViewIntent(messageReference, openInUnifiedInbox) - return PendingIntent.getActivity(context, 0, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE) + return PendingIntentCompat.getActivity(context, 0, intent, FLAG_UPDATE_CURRENT, false)!! } override fun createViewFolderPendingIntent(account: Account, folderId: Long): PendingIntent { val intent = createMessageListIntent(account, folderId) - return PendingIntent.getActivity(context, 0, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE) + return PendingIntentCompat.getActivity(context, 0, intent, FLAG_UPDATE_CURRENT, false)!! } override fun createViewMessagesPendingIntent( @@ -61,41 +61,40 @@ internal class K9NotificationActionCreator( } else { createNewMessagesIntent(account) } - - return PendingIntent.getActivity(context, 0, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE) + return PendingIntentCompat.getActivity(context, 0, intent, FLAG_UPDATE_CURRENT, false)!! } override fun createViewFolderListPendingIntent(account: Account): PendingIntent { val intent = createMessageListIntent(account) - return PendingIntent.getActivity(context, 0, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE) + return PendingIntentCompat.getActivity(context, 0, intent, FLAG_UPDATE_CURRENT, false)!! } override fun createDismissAllMessagesPendingIntent(account: Account): PendingIntent { val intent = NotificationActionService.createDismissAllMessagesIntent(context, account).apply { data = Uri.parse("data:,dismissAll/${account.uuid}/${System.currentTimeMillis()}") } - return PendingIntent.getService(context, 0, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE) + return PendingIntentCompat.getService(context, 0, intent, FLAG_UPDATE_CURRENT, false)!! } override fun createDismissMessagePendingIntent(messageReference: MessageReference): PendingIntent { val intent = NotificationActionService.createDismissMessageIntent(context, messageReference).apply { data = Uri.parse("data:,dismiss/${messageReference.toIdentityString()}") } - return PendingIntent.getService(context, 0, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE) + return PendingIntentCompat.getService(context, 0, intent, FLAG_UPDATE_CURRENT, false)!! } override fun createReplyPendingIntent(messageReference: MessageReference): PendingIntent { val intent = MessageActions.getActionReplyIntent(context, messageReference).apply { data = Uri.parse("data:,reply/${messageReference.toIdentityString()}") } - return PendingIntent.getActivity(context, 0, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE) + return PendingIntentCompat.getActivity(context, 0, intent, FLAG_UPDATE_CURRENT, false)!! } override fun createMarkMessageAsReadPendingIntent(messageReference: MessageReference): PendingIntent { val intent = NotificationActionService.createMarkMessageAsReadIntent(context, messageReference).apply { data = Uri.parse("data:,markAsRead/${messageReference.toIdentityString()}") } - return PendingIntent.getService(context, 0, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE) + return PendingIntentCompat.getService(context, 0, intent, FLAG_UPDATE_CURRENT, false)!! } override fun createMarkAllAsReadPendingIntent( @@ -107,17 +106,17 @@ internal class K9NotificationActionCreator( NotificationActionService.createMarkAllAsReadIntent(context, accountUuid, messageReferences).apply { data = Uri.parse("data:,markAllAsRead/$accountUuid/${System.currentTimeMillis()}") } - return PendingIntent.getService(context, 0, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE) + return PendingIntentCompat.getService(context, 0, intent, FLAG_UPDATE_CURRENT, false)!! } override fun getEditIncomingServerSettingsIntent(account: Account): PendingIntent { val intent = FeatureLauncherActivity.getEditIncomingSettingsIntent(context, account.uuid) - return PendingIntent.getActivity(context, account.accountNumber, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE) + return PendingIntentCompat.getActivity(context, account.accountNumber, intent, FLAG_UPDATE_CURRENT, false)!! } override fun getEditOutgoingServerSettingsIntent(account: Account): PendingIntent { val intent = FeatureLauncherActivity.getEditOutgoingSettingsIntent(context, account.uuid) - return PendingIntent.getActivity(context, account.accountNumber, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE) + return PendingIntentCompat.getActivity(context, account.accountNumber, intent, FLAG_UPDATE_CURRENT, false)!! } override fun createDeleteMessagePendingIntent(messageReference: MessageReference): PendingIntent { @@ -132,14 +131,14 @@ internal class K9NotificationActionCreator( val intent = NotificationActionService.createDeleteMessageIntent(context, messageReference).apply { data = Uri.parse("data:,delete/${messageReference.toIdentityString()}") } - return PendingIntent.getService(context, 0, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE) + return PendingIntentCompat.getService(context, 0, intent, FLAG_UPDATE_CURRENT, false)!! } private fun createDeleteConfirmationPendingIntent(messageReference: MessageReference): PendingIntent { val intent = DeleteConfirmationActivity.getIntent(context, messageReference).apply { data = Uri.parse("data:,deleteConfirmation/${messageReference.toIdentityString()}") } - return PendingIntent.getActivity(context, 0, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE) + return PendingIntentCompat.getActivity(context, 0, intent, FLAG_UPDATE_CURRENT, false)!! } override fun createDeleteAllPendingIntent( @@ -157,7 +156,7 @@ internal class K9NotificationActionCreator( val intent = DeleteConfirmationActivity.getIntent(context, messageReferences).apply { data = Uri.parse("data:,deleteAllConfirmation/${System.currentTimeMillis()}") } - return PendingIntent.getActivity(context, 0, intent, FLAG_CANCEL_CURRENT or FLAG_IMMUTABLE) + return PendingIntentCompat.getActivity(context, 0, intent, FLAG_CANCEL_CURRENT, false)!! } private fun getDeleteAllServicePendingIntent( @@ -169,14 +168,14 @@ internal class K9NotificationActionCreator( NotificationActionService.createDeleteAllMessagesIntent(context, accountUuid, messageReferences).apply { data = Uri.parse("data:,deleteAll/$accountUuid/${System.currentTimeMillis()}") } - return PendingIntent.getService(context, 0, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE) + return PendingIntentCompat.getService(context, 0, intent, FLAG_UPDATE_CURRENT, false)!! } override fun createArchiveMessagePendingIntent(messageReference: MessageReference): PendingIntent { val intent = NotificationActionService.createArchiveMessageIntent(context, messageReference).apply { data = Uri.parse("data:,archive/${messageReference.toIdentityString()}") } - return PendingIntent.getService(context, 0, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE) + return PendingIntentCompat.getService(context, 0, intent, FLAG_UPDATE_CURRENT, false)!! } override fun createArchiveAllPendingIntent( @@ -186,14 +185,14 @@ internal class K9NotificationActionCreator( val intent = NotificationActionService.createArchiveAllIntent(context, account, messageReferences).apply { data = Uri.parse("data:,archiveAll/${account.uuid}/${System.currentTimeMillis()}") } - return PendingIntent.getService(context, 0, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE) + return PendingIntentCompat.getService(context, 0, intent, FLAG_UPDATE_CURRENT, false)!! } override fun createMarkMessageAsSpamPendingIntent(messageReference: MessageReference): PendingIntent { val intent = NotificationActionService.createMarkMessageAsSpamIntent(context, messageReference).apply { data = Uri.parse("data:,spam/${messageReference.toIdentityString()}") } - return PendingIntent.getService(context, 0, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE) + return PendingIntentCompat.getService(context, 0, intent, FLAG_UPDATE_CURRENT, false)!! } private fun createMessageListIntent(account: Account): Intent { diff --git a/app/common/src/main/java/com/fsck/k9/provider/UnreadWidgetProvider.kt b/app/common/src/main/java/com/fsck/k9/provider/UnreadWidgetProvider.kt index 1affe7e9d..3deaa7605 100644 --- a/app/common/src/main/java/com/fsck/k9/provider/UnreadWidgetProvider.kt +++ b/app/common/src/main/java/com/fsck/k9/provider/UnreadWidgetProvider.kt @@ -1,6 +1,5 @@ package com.fsck.k9.provider -import android.app.PendingIntent import android.app.PendingIntent.FLAG_UPDATE_CURRENT import android.appwidget.AppWidgetManager import android.appwidget.AppWidgetProvider @@ -8,9 +7,9 @@ import android.content.Context import android.content.Intent import android.view.View import android.widget.RemoteViews +import androidx.core.app.PendingIntentCompat import com.fsck.k9.EarlyInit import com.fsck.k9.common.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 @@ -86,11 +85,12 @@ class UnreadWidgetProvider : AppWidgetProvider(), EarlyInit { } clickIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - val pendingIntent = PendingIntent.getActivity( + val pendingIntent = PendingIntentCompat.getActivity( context, appWidgetId, clickIntent, - FLAG_UPDATE_CURRENT or FLAG_MUTABLE, + FLAG_UPDATE_CURRENT, + true, ) remoteViews.setOnClickPendingIntent(R.id.unread_widget_layout, pendingIntent) diff --git a/app/core/src/main/java/com/fsck/k9/helper/PendingIntentCompat.kt b/app/core/src/main/java/com/fsck/k9/helper/PendingIntentCompat.kt deleted file mode 100644 index b76bbeccd..000000000 --- a/app/core/src/main/java/com/fsck/k9/helper/PendingIntentCompat.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.fsck.k9.helper - -import android.app.PendingIntent -import android.os.Build - -object PendingIntentCompat { - @JvmField - val FLAG_IMMUTABLE = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0 - - @JvmField - val FLAG_MUTABLE = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) PendingIntent.FLAG_MUTABLE else 0 -} diff --git a/app/core/src/main/java/com/fsck/k9/notification/NotificationHelper.kt b/app/core/src/main/java/com/fsck/k9/notification/NotificationHelper.kt index 70791e326..ffd43990d 100644 --- a/app/core/src/main/java/com/fsck/k9/notification/NotificationHelper.kt +++ b/app/core/src/main/java/com/fsck/k9/notification/NotificationHelper.kt @@ -1,7 +1,6 @@ package com.fsck.k9.notification import android.app.Notification -import android.app.PendingIntent import android.content.Context import android.content.Intent import android.net.Uri @@ -9,9 +8,9 @@ import android.os.Build import android.provider.Settings import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat +import androidx.core.app.PendingIntentCompat import com.fsck.k9.Account import com.fsck.k9.K9 -import com.fsck.k9.helper.PendingIntentCompat import com.fsck.k9.notification.NotificationChannelManager.ChannelType import timber.log.Timber @@ -65,7 +64,7 @@ class NotificationHelper( } val notificationSettingsPendingIntent = - PendingIntent.getActivity(context, account.accountNumber, intent, PendingIntentCompat.FLAG_IMMUTABLE) + PendingIntentCompat.getActivity(context, account.accountNumber, intent, 0, false) val notification = createNotificationBuilder(account, ChannelType.MISCELLANEOUS) .setSmallIcon(resourceProvider.iconWarning) diff --git a/app/core/src/main/java/com/fsck/k9/notification/PushNotificationManager.kt b/app/core/src/main/java/com/fsck/k9/notification/PushNotificationManager.kt index 38e890f60..6c2c7b08b 100644 --- a/app/core/src/main/java/com/fsck/k9/notification/PushNotificationManager.kt +++ b/app/core/src/main/java/com/fsck/k9/notification/PushNotificationManager.kt @@ -1,13 +1,12 @@ package com.fsck.k9.notification import android.app.Notification -import android.app.PendingIntent import android.content.Context import android.content.Intent import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat +import androidx.core.app.PendingIntentCompat 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,7 +53,7 @@ internal class PushNotificationManager( addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) setPackage(context.packageName) } - val contentIntent = PendingIntent.getActivity(context, 1, intent, FLAG_IMMUTABLE) + val contentIntent = PendingIntentCompat.getActivity(context, 1, intent, 0, false) return NotificationCompat.Builder(context, notificationChannelManager.pushChannelId) .setSmallIcon(resourceProvider.iconPushNotification) diff --git a/app/ui/message-list-widget/src/main/java/app/k9mail/ui/widget/list/MessageListWidgetProvider.kt b/app/ui/message-list-widget/src/main/java/app/k9mail/ui/widget/list/MessageListWidgetProvider.kt index 025cb5ffd..7c9682efd 100644 --- a/app/ui/message-list-widget/src/main/java/app/k9mail/ui/widget/list/MessageListWidgetProvider.kt +++ b/app/ui/message-list-widget/src/main/java/app/k9mail/ui/widget/list/MessageListWidgetProvider.kt @@ -6,11 +6,10 @@ import android.appwidget.AppWidgetProvider import android.content.Context import android.content.Intent import android.widget.RemoteViews +import androidx.core.app.PendingIntentCompat import com.fsck.k9.activity.MessageCompose import com.fsck.k9.activity.MessageList import com.fsck.k9.activity.MessageList.Companion.intentDisplaySearch -import com.fsck.k9.helper.PendingIntentCompat.FLAG_IMMUTABLE -import com.fsck.k9.helper.PendingIntentCompat.FLAG_MUTABLE import com.fsck.k9.search.SearchAccount.Companion.createUnifiedInboxAccount import org.koin.core.component.KoinComponent import org.koin.core.component.inject @@ -59,8 +58,7 @@ open class MessageListWidgetProvider : AppWidgetProvider(), KoinComponent { openInUnifiedInbox = true, messageViewOnly = true, ) - - return PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT or FLAG_MUTABLE) + return PendingIntentCompat.getActivity(context, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT, true)!! } private fun viewUnifiedInboxPendingIntent(context: Context): PendingIntent { @@ -72,14 +70,13 @@ open class MessageListWidgetProvider : AppWidgetProvider(), KoinComponent { newTask = true, clearTop = true, ) - - return PendingIntent.getActivity(context, -1, intent, PendingIntent.FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE) + return PendingIntentCompat.getActivity(context, -1, intent, PendingIntent.FLAG_UPDATE_CURRENT, false)!! } private fun composeActionPendingIntent(context: Context): PendingIntent { val intent = Intent(context, MessageCompose::class.java).apply { action = MessageCompose.ACTION_COMPOSE } - return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE) + return PendingIntentCompat.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT, false)!! } }