ipc,t/oxr_android: Add FLAG_IMMUTABLE for PendingIntent from S+

Signed-off-by: utzcoz <utzcoz@outlook.com>
This commit is contained in:
utzcoz 2022-05-28 22:44:03 +08:00 committed by Ryan Pavlik
parent 62c87d27d6
commit 34c97c48ef
2 changed files with 24 additions and 10 deletions

View file

@ -82,11 +82,16 @@ class MonadoService : Service(), Watchdog.ShutdownListener {
}
private fun handleStart() {
var flags = 0
// From targeting S+, the PendingIntent needs one of FLAG_IMMUTABLE and FLAG_MUTABLE
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
flags = PendingIntent.FLAG_IMMUTABLE
}
val pendingShutdownIntent = PendingIntent.getForegroundService(
this,
0,
Intent(BuildConfig.SHUTDOWN_ACTION).setPackage(packageName),
0
flags
)
val notification = serviceNotification.buildNotification(this, pendingShutdownIntent)

View file

@ -13,6 +13,7 @@ import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.graphics.drawable.Icon
import android.os.Build
import dagger.hilt.android.qualifiers.ApplicationContext
import org.freedesktop.monado.android_common.AboutActivity
import org.freedesktop.monado.auxiliary.UiProvider
@ -29,14 +30,22 @@ class MonadoOpenXrUiProvider @Inject constructor(@ApplicationContext val context
/**
* Make a {@code PendingIntent} to launch an "About" activity for the runtime/target.
*/
override fun makeAboutActivityPendingIntent(): PendingIntent =
PendingIntent.getActivity(context,
0,
Intent.makeMainActivity(
ComponentName.createRelative(context,
AboutActivity::class.qualifiedName!!)),
0
)
override fun makeAboutActivityPendingIntent(): PendingIntent {
var flags = 0
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
flags = PendingIntent.FLAG_IMMUTABLE
}
return PendingIntent.getActivity(
context,
0,
Intent.makeMainActivity(
ComponentName.createRelative(
context,
AboutActivity::class.qualifiedName!!
)
),
flags
)
}
}