Display and control your Android device
Rename audio capture exception
Romain Vimont3b8ec0c38db4
diff --git a/server/src/main/java/com/genymobile/scrcpy/audio/AudioCapture.java b/server/src/main/java/com/genymobile/scrcpy/audio/AudioCapture.javaindex 414bfa5d..1da2221e 100644--- a/server/src/main/java/com/genymobile/scrcpy/audio/AudioCapture.java+++ b/server/src/main/java/com/genymobile/scrcpy/audio/AudioCapture.java@@ -89,7 +89,7 @@ public final class AudioCapture {ServiceManager.getActivityManager().forceStopPackage(FakeContext.PACKAGE_NAME);}- private void tryStartRecording(int attempts, int delayMs) throws AudioCaptureForegroundException {+ private void tryStartRecording(int attempts, int delayMs) throws AudioCaptureException {while (attempts-- > 0) {// Wait for activity to startSystemClock.sleep(delayMs);@@ -101,7 +101,7 @@ public final class AudioCapture {Ln.e("Failed to start audio capture");Ln.e("On Android 11, audio capture must be started in the foreground, make sure that the device is unlocked when starting "+ "scrcpy.");- throw new AudioCaptureForegroundException();+ throw new AudioCaptureException();} else {Ln.d("Failed to start audio capture, retrying...");}@@ -121,7 +121,7 @@ public final class AudioCapture {recorder.startRecording();}- public void start() throws AudioCaptureForegroundException {+ public void start() throws AudioCaptureException {if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R) {startWorkaroundAndroid11();try {diff --git a/server/src/main/java/com/genymobile/scrcpy/audio/AudioCaptureException.java b/server/src/main/java/com/genymobile/scrcpy/audio/AudioCaptureException.javanew file mode 100644index 00000000..4b0b7e83--- /dev/null+++ b/server/src/main/java/com/genymobile/scrcpy/audio/AudioCaptureException.java@@ -0,0 +1,12 @@+package com.genymobile.scrcpy.audio;++/**+ * Exception for any audio capture issue.+ * <p/>+ * This includes the case where audio capture failed on Android 11 specifically because the running App (Shell) was not in foreground.+ * <p/>+ * Its purpose is to disable audio without errors (that's why the exception is empty, any error message must be printed by the caller before+ * throwing the exception).+ */+public class AudioCaptureException extends Exception {+}diff --git a/server/src/main/java/com/genymobile/scrcpy/audio/AudioCaptureForegroundException.java b/server/src/main/java/com/genymobile/scrcpy/audio/AudioCaptureForegroundException.javadeleted file mode 100644index 49cfe70f..00000000--- a/server/src/main/java/com/genymobile/scrcpy/audio/AudioCaptureForegroundException.java+++ /dev/null@@ -1,7 +0,0 @@-package com.genymobile.scrcpy.audio;--/**- * Exception thrown if audio capture failed on Android 11 specifically because the running App (shell) was not in foreground.- */-public class AudioCaptureForegroundException extends Exception {-}diff --git a/server/src/main/java/com/genymobile/scrcpy/audio/AudioEncoder.java b/server/src/main/java/com/genymobile/scrcpy/audio/AudioEncoder.javaindex e45284af..219e2c0c 100644--- a/server/src/main/java/com/genymobile/scrcpy/audio/AudioEncoder.java+++ b/server/src/main/java/com/genymobile/scrcpy/audio/AudioEncoder.java@@ -132,7 +132,7 @@ public final class AudioEncoder implements AsyncProcessor {} catch (ConfigurationException e) {// Do not print stack trace, a user-friendly error-message has already been loggedfatalError = true;- } catch (AudioCaptureForegroundException e) {+ } catch (AudioCaptureException e) {// Do not print stack trace, a user-friendly error-message has already been logged} catch (IOException e) {Ln.e("Audio encoding error", e);@@ -176,7 +176,7 @@ public final class AudioEncoder implements AsyncProcessor {}@TargetApi(Build.VERSION_CODES.M)- private void encode() throws IOException, ConfigurationException, AudioCaptureForegroundException {+ private void encode() throws IOException, ConfigurationException, AudioCaptureException {if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {Ln.w("Audio disabled: it is not supported before Android 11");streamer.writeDisableStream(false);diff --git a/server/src/main/java/com/genymobile/scrcpy/audio/AudioRawRecorder.java b/server/src/main/java/com/genymobile/scrcpy/audio/AudioRawRecorder.javaindex 72527600..c7279a3a 100644--- a/server/src/main/java/com/genymobile/scrcpy/audio/AudioRawRecorder.java+++ b/server/src/main/java/com/genymobile/scrcpy/audio/AudioRawRecorder.java@@ -23,7 +23,7 @@ public final class AudioRawRecorder implements AsyncProcessor {this.streamer = streamer;}- private void record() throws IOException, AudioCaptureForegroundException {+ private void record() throws IOException, AudioCaptureException {if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {Ln.w("Audio disabled: it is not supported before Android 11");streamer.writeDisableStream(false);@@ -69,7 +69,7 @@ public final class AudioRawRecorder implements AsyncProcessor {boolean fatalError = false;try {record();- } catch (AudioCaptureForegroundException e) {+ } catch (AudioCaptureException e) {// Do not print stack trace, a user-friendly error-message has already been logged} catch (Throwable t) {Ln.e("Audio recording error", t);