From ffa600a03a50a665f49699f6405519c02a3a6ad0 Mon Sep 17 00:00:00 2001 From: Nathalie Le Clair Date: Thu, 15 Dec 2022 17:52:17 +0100 Subject: [PATCH] Terminate ARC when eARC gets enabled on the RX device MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the RX device has an active ARC connection and eARC disabled, the user may enable eARC in the RX device's settings, i.e. the Audio System's settings. In this scenario, the RX will initiate an eARC connection and should in theory send to terminate the active ARC connection. Even if the RX doesn´t send this message, the TX should send the RX a request to terminate the active ARC connection with a message. The TX should send this message when the HAL reports an EARC_PENDING or EARC_CONNECTED status after the last status update had been ARC_PENDING. Test: atest Bug: 262573690 Change-Id: I8514bcc0858ba6fa744fe2db4c81bdfbed90de22 --- .../server/hdmi/HdmiEarcLocalDeviceTx.java | 8 +++++++ .../server/hdmi/HdmiControlServiceTest.java | 22 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/services/core/java/com/android/server/hdmi/HdmiEarcLocalDeviceTx.java b/services/core/java/com/android/server/hdmi/HdmiEarcLocalDeviceTx.java index bdc30b9f16ad2..abb8439092acd 100644 --- a/services/core/java/com/android/server/hdmi/HdmiEarcLocalDeviceTx.java +++ b/services/core/java/com/android/server/hdmi/HdmiEarcLocalDeviceTx.java @@ -78,9 +78,11 @@ public class HdmiEarcLocalDeviceTx extends HdmiEarcLocalDevice { } protected void handleEarcStateChange(@Constants.EarcStatus int status) { + int oldEarcStatus; synchronized (mLock) { HdmiLogger.debug(TAG, "eARC state change [old:%b new %b]", mEarcStatus, status); + oldEarcStatus = mEarcStatus; mEarcStatus = status; } @@ -91,7 +93,13 @@ public class HdmiEarcLocalDeviceTx extends HdmiEarcLocalDevice { } else if (status == HDMI_EARC_STATUS_ARC_PENDING) { notifyEarcStatusToAudioService(false, new ArrayList<>()); mService.startArcAction(true, null); + } else if (status == HDMI_EARC_STATUS_EARC_PENDING + && oldEarcStatus == HDMI_EARC_STATUS_ARC_PENDING) { + mService.startArcAction(false, null); } else if (status == HDMI_EARC_STATUS_EARC_CONNECTED) { + if (oldEarcStatus == HDMI_EARC_STATUS_ARC_PENDING) { + mService.startArcAction(false, null); + } mReportCapsHandler.postDelayed(mReportCapsRunnable, REPORT_CAPS_MAX_DELAY_MS); } } diff --git a/services/tests/servicestests/src/com/android/server/hdmi/HdmiControlServiceTest.java b/services/tests/servicestests/src/com/android/server/hdmi/HdmiControlServiceTest.java index 1c33fb984ca04..aa49a6222390f 100644 --- a/services/tests/servicestests/src/com/android/server/hdmi/HdmiControlServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/hdmi/HdmiControlServiceTest.java @@ -1319,6 +1319,28 @@ public class HdmiControlServiceTest { verify(mHdmiControlServiceSpy, times(1)).startArcAction(eq(true), any()); } + @Test + public void earcStateWasArcPending_becomesEarcPending_terminateArc() { + mHdmiControlServiceSpy.clearEarcLocalDevice(); + HdmiEarcLocalDeviceTx localDeviceTx = new HdmiEarcLocalDeviceTx(mHdmiControlServiceSpy); + mHdmiControlServiceSpy.addEarcLocalDevice(localDeviceTx); + localDeviceTx.handleEarcStateChange(Constants.HDMI_EARC_STATUS_ARC_PENDING); + mTestLooper.dispatchAll(); + localDeviceTx.handleEarcStateChange(Constants.HDMI_EARC_STATUS_EARC_PENDING); + verify(mHdmiControlServiceSpy, times(1)).startArcAction(eq(false), any()); + } + + @Test + public void earcStateWasArcPending_becomesEarcEnabled_terminateArc() { + mHdmiControlServiceSpy.clearEarcLocalDevice(); + HdmiEarcLocalDeviceTx localDeviceTx = new HdmiEarcLocalDeviceTx(mHdmiControlServiceSpy); + mHdmiControlServiceSpy.addEarcLocalDevice(localDeviceTx); + localDeviceTx.handleEarcStateChange(Constants.HDMI_EARC_STATUS_ARC_PENDING); + mTestLooper.dispatchAll(); + localDeviceTx.handleEarcStateChange(Constants.HDMI_EARC_STATUS_EARC_CONNECTED); + verify(mHdmiControlServiceSpy, times(1)).startArcAction(eq(false), any()); + } + protected static class MockPlaybackDevice extends HdmiCecLocalDevicePlayback { private boolean mCanGoToStandby;