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

Commit 1139559f authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Android (Google) Code Review
Browse files

Merge "CEC: Support arc feature flag for multiple ports"

parents cc975153 5bcf5bf6
Loading
Loading
Loading
Loading
+25 −15
Original line number Original line Diff line number Diff line
@@ -45,6 +45,7 @@ import android.provider.Settings.Global;
import android.util.ArraySet;
import android.util.ArraySet;
import android.util.Slog;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseArray;
import android.util.SparseBooleanArray;


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


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


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


@@ -914,20 +919,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
    @ServiceThreadOnly
    boolean isArcEstabilished() {
    boolean isArcEstablished() {
        assertRunOnServiceThread();
        assertRunOnServiceThread();
        return mArcFeatureEnabled && mArcEstablished;
        if (mArcEstablished) {
            for (int i = 0; i < mArcFeatureEnabled.size(); i++) {
                if (mArcFeatureEnabled.valueAt(i)) return true;
            }
        }
        return false;
    }
    }


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


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


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


    @ServiceThreadOnly
    @ServiceThreadOnly
@@ -1078,7 +1088,7 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
                && isConnectedToArcPort(avr.getPhysicalAddress())
                && isConnectedToArcPort(avr.getPhysicalAddress())
                && isDirectConnectAddress(avr.getPhysicalAddress())) {
                && isDirectConnectAddress(avr.getPhysicalAddress())) {
            if (shouldCheckArcFeatureEnabled) {
            if (shouldCheckArcFeatureEnabled) {
                return isArcFeatureEnabled();
                return isArcFeatureEnabled(avr.getPortId());
            } else {
            } else {
                return true;
                return true;
            }
            }
@@ -1620,7 +1630,7 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {


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


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