From fa7a0252b096cdb6d9b2758a599f36dc0e87f29a Mon Sep 17 00:00:00 2001 From: jiabin Date: Tue, 28 Apr 2020 16:19:47 -0700 Subject: [PATCH] Reset audio port generation when having recording callback event. In RecordingActivityMonitor, compare audio device type and address to know if legacy remote submix is active, which requires querying audio patches. When there is a recording callback event, the audio patches in AudioManager may not be up to date. In that case, when getting a recording callback event, reset audio port generation if the patch handle is not found in the cached audio patches. Test: repro steps in the bug Bug: 144063329 Change-Id: Ife5c9a65243d2e85e4cd9480e3b415f8bfddc6f5 --- media/java/android/media/AudioSystem.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/media/java/android/media/AudioSystem.java b/media/java/android/media/AudioSystem.java index 2d00010f51ee3..da52cfef6bc6e 100644 --- a/media/java/android/media/AudioSystem.java +++ b/media/java/android/media/AudioSystem.java @@ -686,6 +686,23 @@ public class AudioSystem String effectName = effects.length == 0 ? "None" : effects[0].name; if (cb != null) { + ArrayList audioPatches = new ArrayList<>(); + if (AudioManager.listAudioPatches(audioPatches) == AudioManager.SUCCESS) { + boolean patchFound = false; + int patchHandle = recordingFormat[6]; + for (AudioPatch patch : audioPatches) { + if (patch.id() == patchHandle) { + patchFound = true; + break; + } + } + if (!patchFound) { + // The cached audio patches in AudioManager is not up-to-date. + // Reset audio port generation to ensure callback side can + // get up-to-date audio port information. + AudioManager.resetAudioPortGeneration(); + } + } // TODO receive package name from native cb.onRecordingConfigurationChanged(event, riid, uid, session, source, portId, silenced, recordingFormat, clientEffects, effects, activeSource, "");