Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 88909ce5 authored by Donghyun Cho's avatar Donghyun Cho
Browse files

CEC: Use isConnected() to check ARC transmission feasibility

Whenever every hotplug event occurs, ARC feature has been
disabled/enabled if needed in order not to establish ARC connection if
+5V status is false. The check, whether feature should be
disabled/enabled or not, is based on the device info of AVR. But it may
malfunction if the device info is stale because of rapid and repeated
plug in/out. This change simplifies this check by using isConnected()
instead of disabling/enabling full ARC feature.

Bug: 33567002
Test: Applied this change and plug in/out rapidly on archer.
Change-Id: I420270193d2f60f61f3c39a151c7e06d326651d2
(cherry picked from commit b0fd6a1bed5d522673233fbd51d1d7508c790c0c)
parent 8ae761f7
Loading
Loading
Loading
Loading
+16 −40
Original line number Diff line number Diff line
@@ -796,7 +796,7 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
    void onNewAvrAdded(HdmiDeviceInfo avr) {
        assertRunOnServiceThread();
        addAndStartAction(new SystemAudioAutoInitiationAction(this, avr.getLogicalAddress()));
        if (isArcFeatureEnabled(avr.getPortId())
        if (isConnected(avr.getPortId()) && isArcFeatureEnabled(avr.getPortId())
                && !hasAction(SetArcTransmissionStateAction.class)) {
            startArcAction(true);
        }
@@ -899,29 +899,6 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        }
    }

    @ServiceThreadOnly
    private void updateArcFeatureStatus(int portId, boolean isConnected) {
        assertRunOnServiceThread();
        HdmiPortInfo portInfo = mService.getPortInfo(portId);
        if (!portInfo.isArcSupported()) {
            return;
        }
        HdmiDeviceInfo avr = getAvrDeviceInfo();
        if (avr == null) {
            if (isConnected) {
                // Update the status (since TV may not have seen AVR yet) so
                // that ARC can be initiated after discovery.
                mArcFeatureEnabled.put(portId, isConnected);
            }
            return;
        }
        // HEAC 2.4, HEACT 5-15
        // Should not activate ARC if +5V status is false.
        if (avr.getPortId() == portId) {
            changeArcFeatureEnabled(portId, isConnected);
        }
    }

    @ServiceThreadOnly
    boolean isConnected(int portId) {
        assertRunOnServiceThread();
@@ -952,20 +929,20 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
    @ServiceThreadOnly
    void changeArcFeatureEnabled(int portId, boolean enabled) {
        assertRunOnServiceThread();

        if (mArcFeatureEnabled.get(portId) != enabled) {
        if (mArcFeatureEnabled.get(portId) == enabled) {
            return;
        }
        mArcFeatureEnabled.put(portId, enabled);
            if (enabled) {
                if (!mArcEstablished) {
                    startArcAction(true);
        HdmiDeviceInfo avr = getAvrDeviceInfo();
        if (avr == null || avr.getPortId() != portId) {
            return;
        }
            } else {
                if (mArcEstablished) {
        if (enabled && !mArcEstablished) {
            startArcAction(true);
        } else if (!enabled && mArcEstablished) {
            startArcAction(false);
        }
    }
        }
    }

    @ServiceThreadOnly
    boolean isArcFeatureEnabled(int portId) {
@@ -1097,14 +1074,14 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        return true;
    }

    private boolean canStartArcUpdateAction(int avrAddress, boolean shouldCheckArcFeatureEnabled) {
    private boolean canStartArcUpdateAction(int avrAddress, boolean enabled) {
        HdmiDeviceInfo avr = getAvrDeviceInfo();
        if (avr != null
                && (avrAddress == avr.getLogicalAddress())
                && isConnectedToArcPort(avr.getPhysicalAddress())
                && isDirectConnectAddress(avr.getPhysicalAddress())) {
            if (shouldCheckArcFeatureEnabled) {
                return isArcFeatureEnabled(avr.getPortId());
            if (enabled) {
                return isConnected(avr.getPortId()) && isArcFeatureEnabled(avr.getPortId());
            } else {
                return true;
            }
@@ -1566,7 +1543,6 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
            // It covers seq #40, #43.
            hotplugActions.get(0).pollAllDevicesNow();
        }
        updateArcFeatureStatus(portId, connected);
    }

    private void removeCecSwitches(int portId) {