From 1412a1d20c04982ead48c57a78b7bdbaf9b13adb Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Tue, 24 Nov 2020 11:13:20 -0800 Subject: [PATCH] AudioRecord: ensure documented behavior of active rec config Make sure getActiveRecordingConfiguration() doesn't throw an exception when queried after the recorder is released as this isn't part of the API contract Bug: 170608713 Test: atest android.media.cts.AudioRecordTest#testGetActiveRecordingConfiguration Change-Id: I8003056e65ab0e125b5478d6c765878b2840d4b9 --- media/java/android/media/AudioRecord.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/media/java/android/media/AudioRecord.java b/media/java/android/media/AudioRecord.java index c9cdbb0ed2771..6570aabf8e2dc 100644 --- a/media/java/android/media/AudioRecord.java +++ b/media/java/android/media/AudioRecord.java @@ -165,6 +165,7 @@ public class AudioRecord implements AudioRouting, MicrophoneDirection, //-------------------- /** * Accessed by native methods: provides access to C++ AudioRecord object + * Is 0 after release() */ @SuppressWarnings("unused") @UnsupportedAppUsage @@ -1863,7 +1864,11 @@ public class AudioRecord implements AudioRouting, MicrophoneDirection, if (mNativeRecorderInJavaObj == 0) { return 0; } - return native_getPortId(); + try { + return native_getPortId(); + } catch (IllegalStateException e) { + return 0; + } } //-------------------------------------------------------------------------- @@ -2046,6 +2051,9 @@ public class AudioRecord implements AudioRouting, MicrophoneDirection, private native final int native_get_active_microphones( ArrayList activeMicrophones); + /** + * @throws IllegalStateException + */ private native int native_getPortId(); private native int native_set_preferred_microphone_direction(int direction);