From fdf465851c786f153255d044c621c1ac4766e5fd Mon Sep 17 00:00:00 2001 From: Simon Chan <1330321+yume-chan@users.noreply.github.com> Date: Tue, 4 Apr 2023 22:33:39 +0800 Subject: [PATCH] Add Android version check in raw audio recorder Do not attempt to capture audio below Android 11, this may cause a segfault on the device. PR #3889 Signed-off-by: Romain Vimont --- .../main/java/com/genymobile/scrcpy/AudioRawRecorder.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/src/main/java/com/genymobile/scrcpy/AudioRawRecorder.java b/server/src/main/java/com/genymobile/scrcpy/AudioRawRecorder.java index 4b1b5bd0..f98440de 100644 --- a/server/src/main/java/com/genymobile/scrcpy/AudioRawRecorder.java +++ b/server/src/main/java/com/genymobile/scrcpy/AudioRawRecorder.java @@ -1,6 +1,7 @@ package com.genymobile.scrcpy; import android.media.MediaCodec; +import android.os.Build; import java.io.IOException; import java.nio.ByteBuffer; @@ -19,6 +20,12 @@ public final class AudioRawRecorder implements AsyncProcessor { } private void record() throws IOException, AudioCaptureForegroundException { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { + Ln.w("Audio disabled: it is not supported before Android 11"); + streamer.writeDisableStream(false); + return; + } + final ByteBuffer buffer = ByteBuffer.allocateDirect(READ_SIZE); final MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();