Replace `PendingIntentCompat by Android version

This commit is contained in:
Wolf-Martell Montwé 2024-02-27 16:58:35 +01:00
parent 56fa185b3a
commit e981e05079
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
7 changed files with 33 additions and 51 deletions

View file

@ -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<Callback?>(null)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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