Skip to content

Commit

Permalink
Throw AudioCaptureException on workaround error
Browse files Browse the repository at this point in the history
Replace a RuntimeException by a specific AudioCaptureException.

PR Genymobile#5102 <Genymobile#5102>
  • Loading branch information
rom1v authored and FreedomBen committed Aug 2, 2024
1 parent ab8497f commit 49c2c52
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions server/src/main/java/com/genymobile/scrcpy/Workarounds.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.genymobile.scrcpy;

import com.genymobile.scrcpy.audio.AudioCaptureException;
import com.genymobile.scrcpy.util.Ln;

import android.annotation.SuppressLint;
Expand Down Expand Up @@ -195,7 +196,8 @@ static Context getSystemContext() {

@TargetApi(Build.VERSION_CODES.R)
@SuppressLint("WrongConstant,MissingPermission")
public static AudioRecord createAudioRecord(int source, int sampleRate, int channelConfig, int channels, int channelMask, int encoding) {
public static AudioRecord createAudioRecord(int source, int sampleRate, int channelConfig, int channels, int channelMask, int encoding) throws
AudioCaptureException {
// Vivo (and maybe some other third-party ROMs) modified `AudioRecord`'s constructor, requiring `Context`s from real App environment.
//
// This method invokes the `AudioRecord(long nativeRecordInJavaObj)` constructor to create an empty `AudioRecord` instance, then uses
Expand Down Expand Up @@ -336,8 +338,8 @@ public static AudioRecord createAudioRecord(int source, int sampleRate, int chan

return audioRecord;
} catch (Exception e) {
Ln.e("Failed to invoke AudioRecord.<init>.", e);
throw new RuntimeException("Cannot create AudioRecord");
Ln.e("Cannot create AudioRecord", e);
throw new AudioCaptureException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void tryStartRecording(int attempts, int delayMs) throws AudioCaptureExc
}
}

private void startRecording() {
private void startRecording() throws AudioCaptureException {
try {
recorder = createAudioRecord(audioSource);
} catch (NullPointerException e) {
Expand Down

0 comments on commit 49c2c52

Please sign in to comment.