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

Commit 5bcf5bf6 authored by Jinsuk Kim's avatar Jinsuk Kim
Browse files

CEC: Support arc feature flag for multiple ports

mArcFeatureEnabled is extended to a flag array to correctly
indicate the state of each port that supports ARC.

Bug: 19957954
Change-Id: I63e4dc2ebd4d71c5ebf59118a3076b52b489c2f2
parent 2ea13d42
Loading
Loading
Loading
Loading
+25 −15
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.provider.Settings.Global;
import android.util.ArraySet;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseBooleanArray;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.IndentingPrintWriter;
@@ -71,9 +72,8 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
    @ServiceThreadOnly
    private boolean mArcEstablished = false;

    // Whether ARC feature is enabled or not. The default value is true.
    // TODO: once adding system setting for it, read the value to it.
    private boolean mArcFeatureEnabled = true;
    // Stores whether ARC feature is enabled per port. True by default for all the ARC-enabled ports.
    private final SparseBooleanArray mArcFeatureEnabled = new SparseBooleanArray();

    // Whether System audio mode is activated or not.
    // This becomes true only when all system audio sequences are finished.
@@ -190,6 +190,10 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
    @ServiceThreadOnly
    protected void onAddressAllocated(int logicalAddress, int reason) {
        assertRunOnServiceThread();
        List<HdmiPortInfo> ports = mService.getPortInfo();
        for (HdmiPortInfo port : ports) {
            mArcFeatureEnabled.put(port.getId(), port.isArcSupported());
        }
        mService.registerTvInputCallback(mTvInputCallback);
        mService.sendCecCommand(HdmiCecMessageBuilder.buildReportPhysicalAddressCommand(
                mAddress, mService.getPhysicalAddress(), mDeviceType));
@@ -794,7 +798,8 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        if (getSystemAudioModeSetting() && !isSystemAudioActivated()) {
            addAndStartAction(new SystemAudioAutoInitiationAction(this, avr.getLogicalAddress()));
        }
        if (isArcFeatureEnabled() && !hasAction(SetArcTransmissionStateAction.class)) {
        if (isArcFeatureEnabled(avr.getPortId())
                && !hasAction(SetArcTransmissionStateAction.class)) {
            startArcAction(true);
        }
    }
@@ -903,7 +908,7 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        // Should not activate ARC if +5V status is false.
        HdmiPortInfo portInfo = mService.getPortInfo(portId);
        if (portInfo.isArcSupported()) {
            changeArcFeatureEnabled(isConnected);
            changeArcFeatureEnabled(portId, isConnected);
        }
    }

@@ -915,20 +920,25 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
    }

    /**
     * Returns whether ARC is enabled or not.
     * Returns true if ARC is currently established on a certain port.
     */
    @ServiceThreadOnly
    boolean isArcEstabilished() {
    boolean isArcEstablished() {
        assertRunOnServiceThread();
        return mArcFeatureEnabled && mArcEstablished;
        if (mArcEstablished) {
            for (int i = 0; i < mArcFeatureEnabled.size(); i++) {
                if (mArcFeatureEnabled.valueAt(i)) return true;
            }
        }
        return false;
    }

    @ServiceThreadOnly
    void changeArcFeatureEnabled(boolean enabled) {
    void changeArcFeatureEnabled(int portId, boolean enabled) {
        assertRunOnServiceThread();

        if (mArcFeatureEnabled != enabled) {
            mArcFeatureEnabled = enabled;
        if (mArcFeatureEnabled.get(portId) != enabled) {
            mArcFeatureEnabled.put(portId, enabled);
            if (enabled) {
                if (!mArcEstablished) {
                    startArcAction(true);
@@ -942,9 +952,9 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
    }

    @ServiceThreadOnly
    boolean isArcFeatureEnabled() {
    boolean isArcFeatureEnabled(int portId) {
        assertRunOnServiceThread();
        return mArcFeatureEnabled;
        return mArcFeatureEnabled.get(portId);
    }

    @ServiceThreadOnly
@@ -1079,7 +1089,7 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
                && isConnectedToArcPort(avr.getPhysicalAddress())
                && isDirectConnectAddress(avr.getPhysicalAddress())) {
            if (shouldCheckArcFeatureEnabled) {
                return isArcFeatureEnabled();
                return isArcFeatureEnabled(avr.getPortId());
            } else {
                return true;
            }
@@ -1621,7 +1631,7 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {

        // Seq #44.
        removeAction(RequestArcInitiationAction.class);
        if (!hasAction(RequestArcTerminationAction.class) && isArcEstabilished()) {
        if (!hasAction(RequestArcTerminationAction.class) && isArcEstablished()) {
            addAndStartAction(new RequestArcTerminationAction(this, avr.getLogicalAddress()));
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -261,7 +261,7 @@ final class HotplugDetectionAction extends HdmiCecFeatureAction {

        // Turn off system audio mode and update settings.
        tv().setSystemAudioMode(false, true);
        if (tv().isArcEstabilished()) {
        if (tv().isArcEstablished()) {
            tv().setAudioReturnChannel(false);
            addAndStartAction(new RequestArcTerminationAction(localDevice(), address));
        }