Skip to content

Commit f976c17

Browse files
committed
fix: re-added the force non-null assertion operator and add fallback when intent cloning fails
1 parent cda05f5 commit f976c17

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

app/src/main/java/io/github/fate_grand_automata/runner/ScreenshotServiceHolder.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,15 @@ class ScreenshotServiceHolder @Inject constructor(
5353
throw IllegalStateException("Media projection token is null")
5454
}
5555
val token = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
56-
ScriptRunnerService.mediaProjectionToken
56+
ScriptRunnerService.mediaProjectionToken!!
5757
} else {
58-
// Cloning the Intent allows reuse.
59-
// Otherwise, the Intent gets consumed and MediaProjection cannot be started multiple times.
60-
ScriptRunnerService.mediaProjectionToken.clone() as Intent
58+
try {
59+
// Cloning the Intent allows reuse.
60+
// Otherwise, the Intent gets consumed and MediaProjection cannot be started multiple times.
61+
ScriptRunnerService.mediaProjectionToken?.clone() as Intent
62+
} catch (e: Exception) {
63+
ScriptRunnerService.mediaProjectionToken!!
64+
}
6165
}
6266

6367
val mediaProjection =

0 commit comments

Comments
 (0)