srctree

Robin Linden parent 0eb524a8 9b5e8def
Target Android 12

This commit includes specifying the mutability of pending intents.

inlinesplit
filename was Deleted added: 45, removed: 10, total 35
@@ -0,0 +1,33 @@
// SPDX-FileCopyrightText: 2021 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: GPL-3.0-only
 
package ltd.evilcorp.atox
 
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
 
object PendingIntentCompat {
fun getBroadcast(
context: Context,
requestCode: Int,
intent: Intent,
flags: Int,
mutable: Boolean = false
): PendingIntent =
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
PendingIntent.getBroadcast(context, requestCode, intent, flags)
} else {
val mutabilityFlag = if (mutable) PendingIntent.FLAG_MUTABLE else PendingIntent.FLAG_IMMUTABLE
PendingIntent.getBroadcast(context, requestCode, intent, flags or mutabilityFlag)
}
 
fun getActivity(context: Context, requestCode: Int, intent: Intent, flags: Int): PendingIntent =
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
PendingIntent.getActivity(context, requestCode, intent, flags)
} else {
PendingIntent.getActivity(context, requestCode, intent, flags or PendingIntent.FLAG_IMMUTABLE)
}
}
 
atox/src/main/kotlin/ToxService.kt added: 45, removed: 10, total 35
@@ -63,7 +63,7 @@ class ToxService : LifecycleService() {
private fun notificationFor(status: ConnectionStatus?): Notification {
val pendingIntent: PendingIntent =
Intent(this, MainActivity::class.java).let { notificationIntent ->
PendingIntent.getActivity(this, 0, notificationIntent, 0)
PendingIntentCompat.getActivity(this, 0, notificationIntent, 0)
}
 
return NotificationCompat.Builder(this, channelId)
 
atox/src/main/kotlin/ui/NotificationHelper.kt added: 45, removed: 10, total 35
@@ -32,6 +32,7 @@ import ltd.evilcorp.atox.ActionReceiver
import ltd.evilcorp.atox.KEY_CALL
import ltd.evilcorp.atox.KEY_CONTACT_PK
import ltd.evilcorp.atox.KEY_TEXT_REPLY
import ltd.evilcorp.atox.PendingIntentCompat
import ltd.evilcorp.atox.R
import ltd.evilcorp.atox.ui.chat.CONTACT_PUBLIC_KEY
import ltd.evilcorp.core.vo.Contact
@@ -112,11 +113,12 @@ class NotificationHelper @Inject constructor(
.Builder(
IconCompat.createWithResource(context, R.drawable.send),
context.getString(R.string.reply),
PendingIntent.getBroadcast(
PendingIntentCompat.getBroadcast(
context,
contact.publicKey.hashCode(),
Intent(context, ActionReceiver::class.java).putExtra(KEY_CONTACT_PK, contact.publicKey),
PendingIntent.FLAG_UPDATE_CURRENT
PendingIntent.FLAG_UPDATE_CURRENT,
mutable = true,
)
)
.addRemoteInput(
@@ -226,7 +228,7 @@ class NotificationHelper @Inject constructor(
.Builder(
IconCompat.createWithResource(context, R.drawable.ic_call),
context.getString(R.string.accept),
PendingIntent.getBroadcast(
PendingIntentCompat.getBroadcast(
context,
"${c.publicKey}_accept_call".hashCode(),
Intent(context, ActionReceiver::class.java)
@@ -243,7 +245,7 @@ class NotificationHelper @Inject constructor(
.Builder(
IconCompat.createWithResource(context, R.drawable.ic_not_interested),
context.getString(R.string.reject),
PendingIntent.getBroadcast(
PendingIntentCompat.getBroadcast(
context,
"${c.publicKey}_reject_call".hashCode(),
Intent(context, ActionReceiver::class.java)
 
buildSrc/src/main/kotlin/Dependencies.kt added: 45, removed: 10, total 35
@@ -23,7 +23,7 @@ object BuildPlugin {
 
object AndroidSdk {
const val minVersion = 19
const val targetVersion = 30
const val targetVersion = 31
}
 
object JavaX {