From 07600116b59e2accd1e95b9029c2c9819cd76c5a Mon Sep 17 00:00:00 2001 From: Jinsuk Kim Date: Thu, 29 Jan 2015 07:34:34 +0900 Subject: [PATCH] CEC: Ensure stable AVR connection Make sure AVR device removal due to hotplug detection failure occur in a less strict manner - doing it only if the failure is detected 3 times in a row. Bug: 19171321 Change-Id: I1479663b05cdc957cc52123799c756f6b74f6708 --- .../server/hdmi/HotplugDetectionAction.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/services/core/java/com/android/server/hdmi/HotplugDetectionAction.java b/services/core/java/com/android/server/hdmi/HotplugDetectionAction.java index 722be713bdf6d..1bbd038e7f4d6 100644 --- a/services/core/java/com/android/server/hdmi/HotplugDetectionAction.java +++ b/services/core/java/com/android/server/hdmi/HotplugDetectionAction.java @@ -38,6 +38,7 @@ final class HotplugDetectionAction extends HdmiCecFeatureAction { private static final int POLLING_INTERVAL_MS = 5000; private static final int TIMEOUT_COUNT = 3; + private static final int AVR_COUNT_MAX = 3; // State in which waits for next polling private static final int STATE_WAIT_FOR_NEXT_POLLING = 1; @@ -48,6 +49,12 @@ final class HotplugDetectionAction extends HdmiCecFeatureAction { private int mTimeoutCount = 0; + // Counter used to ensure the connection to AVR is stable. Occasional failure to get + // polling response from AVR despite its presence leads to unstable status flipping. + // This is a workaround to deal with it, by removing the device only if the removal + // is detected {@code AVR_COUNT_MAX} times in a row. + private int mAvrStatusCount = 0; + /** * Constructor * @@ -148,10 +155,22 @@ final class HotplugDetectionAction extends HdmiCecFeatureAction { BitSet removed = complement(currentInfos, polledResult); int index = -1; while ((index = removed.nextSetBit(index + 1)) != -1) { + if (index == Constants.ADDR_AUDIO_SYSTEM) { + ++mAvrStatusCount; + Slog.w(TAG, "Ack not returned from AVR. count: " + mAvrStatusCount); + if (mAvrStatusCount < AVR_COUNT_MAX) { + continue; + } + } Slog.v(TAG, "Remove device by hot-plug detection:" + index); removeDevice(index); } + // Reset the counter if the ack is returned from AVR. + if (!removed.get(Constants.ADDR_AUDIO_SYSTEM)) { + mAvrStatusCount = 0; + } + // Next, check added devices. BitSet added = complement(polledResult, currentInfos); index = -1;