From daba5638c6b6ea7bb448edfb4c040503c88c7992 Mon Sep 17 00:00:00 2001 From: reconman Date: Thu, 15 Aug 2024 13:13:57 +0200 Subject: [PATCH] Don't reuse MediaProjection tokens on Android 14 --- .../fate_grand_automata/runner/ScreenshotServiceHolder.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/java/io/github/fate_grand_automata/runner/ScreenshotServiceHolder.kt b/app/src/main/java/io/github/fate_grand_automata/runner/ScreenshotServiceHolder.kt index eef36b5a7..dd2db8d7e 100644 --- a/app/src/main/java/io/github/fate_grand_automata/runner/ScreenshotServiceHolder.kt +++ b/app/src/main/java/io/github/fate_grand_automata/runner/ScreenshotServiceHolder.kt @@ -3,6 +3,7 @@ package io.github.fate_grand_automata.runner import android.app.Activity import android.content.Intent import android.media.projection.MediaProjectionManager +import android.os.Build import dagger.hilt.android.scopes.ServiceScoped import io.github.fate_grand_automata.imaging.MediaProjectionScreenshotService import io.github.fate_grand_automata.root.RootScreenshotService @@ -55,6 +56,11 @@ class ScreenshotServiceHolder @Inject constructor( val mediaProjection = mediaProjectionManager.getMediaProjection(Activity.RESULT_OK, token) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + // not allowed to reuse tokens on Android 14 + ScriptRunnerService.mediaProjectionToken = null + } + val scaledSize = size * (scale ?: 1.0) val scaledDensity = (landscapeMetrics.densityDpi / (scale ?: 1.0)).roundToInt()