Aperture: Allow background launch for QR code pending intents

Fixes: https://gitlab.com/LineageOS/issues/android/-/issues/6912
Change-Id: I8d3808b84048e8057cea4b088fb3765ef94d00e4
diff --git a/app/src/main/java/org/lineageos/aperture/ext/PendingIntent.kt b/app/src/main/java/org/lineageos/aperture/ext/PendingIntent.kt
new file mode 100644
index 0000000..6681d6d
--- /dev/null
+++ b/app/src/main/java/org/lineageos/aperture/ext/PendingIntent.kt
@@ -0,0 +1,21 @@
+/*
+ * SPDX-FileCopyrightText: 2024 The LineageOS Project
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package org.lineageos.aperture.ext
+
+import android.app.ActivityOptions
+import android.app.PendingIntent
+import android.os.Build
+
+fun PendingIntent.sendWithBalAllowed() =
+    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
+        send(
+            ActivityOptions.makeBasic().setPendingIntentBackgroundActivityStartMode(
+                ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED
+            ).toBundle()
+        )
+    } else {
+        send()
+    }
diff --git a/app/src/main/java/org/lineageos/aperture/qr/QrImageAnalyzer.kt b/app/src/main/java/org/lineageos/aperture/qr/QrImageAnalyzer.kt
index 4c7ad64..354ca89 100644
--- a/app/src/main/java/org/lineageos/aperture/qr/QrImageAnalyzer.kt
+++ b/app/src/main/java/org/lineageos/aperture/qr/QrImageAnalyzer.kt
@@ -124,7 +124,7 @@
                 with(textClassification.actions[0]) {
                     bottomSheetDialogCardView.setOnClickListener {
                         try {
-                            actionIntent.send()
+                            actionIntent.sendWithBalAllowed()
                         } catch (e: PendingIntent.CanceledException) {
                             Toast.makeText(
                                 activity,
@@ -142,7 +142,7 @@
                     bottomSheetDialogActionsLayout.addView(inflateButton().apply {
                         setOnClickListener {
                             try {
-                                action.actionIntent.send()
+                                action.actionIntent.sendWithBalAllowed()
                             } catch (e: PendingIntent.CanceledException) {
                                 Toast.makeText(
                                     activity,