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

Commit 2c70cd58 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I944dc1cd,I97c962d5

* changes:
  Track CEC version of CEC devices
  Add HdmiDeviceInfo#mHdmiCecVersion
parents 9e75ca54 17c51c7b
Loading
Loading
Loading
Loading
+44 −3
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.hardware.hdmi;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.hardware.hdmi.HdmiControlManager.HdmiCecVersion;
import android.os.Parcel;
import android.os.Parcelable;

@@ -107,6 +108,8 @@ public class HdmiDeviceInfo implements Parcelable {
    // CEC only parameters.
    private final int mLogicalAddress;
    private final int mDeviceType;
    @HdmiCecVersion
    private final int mHdmiCecVersion;
    private final int mVendorId;
    private final String mDisplayName;
    private final int mDevicePowerStatus;
@@ -133,8 +136,9 @@ public class HdmiDeviceInfo implements Parcelable {
                            int vendorId = source.readInt();
                            int powerStatus = source.readInt();
                            String displayName = source.readString();
                            int cecVersion = source.readInt();
                            return new HdmiDeviceInfo(logicalAddress, physicalAddress, portId,
                                    deviceType, vendorId, displayName, powerStatus);
                                    deviceType, vendorId, displayName, powerStatus, cecVersion);
                        case HDMI_DEVICE_TYPE_MHL:
                            int deviceId = source.readInt();
                            int adopterId = source.readInt();
@@ -167,7 +171,7 @@ public class HdmiDeviceInfo implements Parcelable {
     * @hide
     */
    public HdmiDeviceInfo(int logicalAddress, int physicalAddress, int portId, int deviceType,
            int vendorId, String displayName, int powerStatus) {
            int vendorId, String displayName, int powerStatus, int hdmiCecVersion) {
        mHdmiDeviceType = HDMI_DEVICE_TYPE_CEC;
        mPhysicalAddress = physicalAddress;
        mPortId = portId;
@@ -175,6 +179,7 @@ public class HdmiDeviceInfo implements Parcelable {
        mId = idForCecDevice(logicalAddress);
        mLogicalAddress = logicalAddress;
        mDeviceType = deviceType;
        mHdmiCecVersion = hdmiCecVersion;
        mVendorId = vendorId;
        mDevicePowerStatus = powerStatus;
        mDisplayName = displayName;
@@ -183,6 +188,24 @@ public class HdmiDeviceInfo implements Parcelable {
        mAdopterId = -1;
    }

    /**
     * Constructor. Used to initialize the instance for CEC device.
     *
     * @param logicalAddress logical address of HDMI-CEC device
     * @param physicalAddress physical address of HDMI-CEC device
     * @param portId HDMI port ID (1 for HDMI1)
     * @param deviceType type of device
     * @param vendorId vendor id of device. Used for vendor specific command.
     * @param displayName name of device
     * @param powerStatus device power status
     * @hide
     */
    public HdmiDeviceInfo(int logicalAddress, int physicalAddress, int portId, int deviceType,
            int vendorId, String displayName, int powerStatus) {
        this(logicalAddress, physicalAddress, portId, deviceType,
                vendorId, displayName, powerStatus, HdmiControlManager.HDMI_CEC_VERSION_1_4_b);
    }

    /**
     * Constructor. Used to initialize the instance for CEC device.
     *
@@ -197,7 +220,8 @@ public class HdmiDeviceInfo implements Parcelable {
    public HdmiDeviceInfo(int logicalAddress, int physicalAddress, int portId, int deviceType,
            int vendorId, String displayName) {
        this(logicalAddress, physicalAddress, portId, deviceType,
                vendorId, displayName, HdmiControlManager.POWER_STATUS_UNKNOWN);
                vendorId, displayName, HdmiControlManager.POWER_STATUS_UNKNOWN,
                HdmiControlManager.HDMI_CEC_VERSION_1_4_b);
    }

    /**
@@ -215,6 +239,7 @@ public class HdmiDeviceInfo implements Parcelable {
        mId = idForHardware(portId);
        mLogicalAddress = -1;
        mDeviceType = DEVICE_RESERVED;
        mHdmiCecVersion = HdmiControlManager.HDMI_CEC_VERSION_1_4_b;
        mVendorId = 0;
        mDevicePowerStatus = HdmiControlManager.POWER_STATUS_UNKNOWN;
        mDisplayName = "HDMI" + portId;
@@ -240,6 +265,7 @@ public class HdmiDeviceInfo implements Parcelable {
        mId = idForMhlDevice(portId);
        mLogicalAddress = -1;
        mDeviceType = DEVICE_RESERVED;
        mHdmiCecVersion = HdmiControlManager.HDMI_CEC_VERSION_1_4_b;
        mVendorId = 0;
        mDevicePowerStatus = HdmiControlManager.POWER_STATUS_UNKNOWN;
        mDisplayName = "Mobile";
@@ -261,6 +287,7 @@ public class HdmiDeviceInfo implements Parcelable {

        mLogicalAddress = -1;
        mDeviceType = DEVICE_INACTIVE;
        mHdmiCecVersion = HdmiControlManager.HDMI_CEC_VERSION_1_4_b;
        mPortId = PORT_INVALID;
        mDevicePowerStatus = HdmiControlManager.POWER_STATUS_UNKNOWN;
        mDisplayName = "Inactive";
@@ -338,6 +365,16 @@ public class HdmiDeviceInfo implements Parcelable {
        return mDeviceType;
    }

    /**
     * Returns the CEC version the device supports.
     *
     * @hide
     */
    @HdmiCecVersion
    public int getCecVersion() {
        return mHdmiCecVersion;
    }

    /**
     * Returns device's power status. It should be one of the following values.
     * <ul>
@@ -448,6 +485,7 @@ public class HdmiDeviceInfo implements Parcelable {
                dest.writeInt(mVendorId);
                dest.writeInt(mDevicePowerStatus);
                dest.writeString(mDisplayName);
                dest.writeInt(mHdmiCecVersion);
                break;
            case HDMI_DEVICE_TYPE_MHL:
                dest.writeInt(mDeviceId);
@@ -470,6 +508,7 @@ public class HdmiDeviceInfo implements Parcelable {
                s.append("logical_address: ").append(String.format("0x%02X", mLogicalAddress));
                s.append(" ");
                s.append("device_type: ").append(mDeviceType).append(" ");
                s.append("cec_version: ").append(mHdmiCecVersion).append(" ");
                s.append("vendor_id: ").append(mVendorId).append(" ");
                s.append("display_name: ").append(mDisplayName).append(" ");
                s.append("power_status: ").append(mDevicePowerStatus).append(" ");
@@ -507,6 +546,7 @@ public class HdmiDeviceInfo implements Parcelable {
                && mPortId == other.mPortId
                && mLogicalAddress == other.mLogicalAddress
                && mDeviceType == other.mDeviceType
                && mHdmiCecVersion == other.mHdmiCecVersion
                && mVendorId == other.mVendorId
                && mDevicePowerStatus == other.mDevicePowerStatus
                && mDisplayName.equals(other.mDisplayName)
@@ -522,6 +562,7 @@ public class HdmiDeviceInfo implements Parcelable {
                mPortId,
                mLogicalAddress,
                mDeviceType,
                mHdmiCecVersion,
                mVendorId,
                mDevicePowerStatus,
                mDisplayName,
+11 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ public class HdmiDeviceInfoTest {
        int deviceType = 0;
        int vendorId = 0x123456;
        String displayName = "test device";
        int cecVersion = HdmiControlManager.HDMI_CEC_VERSION_2_0;
        int powerStatus = HdmiControlManager.POWER_STATUS_TRANSIENT_TO_STANDBY;
        int deviceId = 3;
        int adopterId = 2;
@@ -70,6 +71,16 @@ public class HdmiDeviceInfoTest {
                                vendorId,
                                displayName,
                                powerStatus))
                .addEqualityGroup(
                        new HdmiDeviceInfo(
                                logicalAddr,
                                phyAddr,
                                portId,
                                deviceType,
                                vendorId,
                                displayName,
                                powerStatus,
                                cecVersion))
                .testEquals();
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -282,6 +282,8 @@ abstract class HdmiCecLocalDevice {
                return handleGiveOsdName(message);
            case Constants.MESSAGE_GIVE_DEVICE_VENDOR_ID:
                return handleGiveDeviceVendorId(null);
            case Constants.MESSAGE_CEC_VERSION:
                return handleCecVersion();
            case Constants.MESSAGE_GET_CEC_VERSION:
                return handleGetCecVersion(message);
            case Constants.MESSAGE_REPORT_PHYSICAL_ADDRESS:
@@ -405,6 +407,14 @@ abstract class HdmiCecLocalDevice {
        return true;
    }

    @ServiceThreadOnly
    private boolean handleCecVersion() {
        assertRunOnServiceThread();

        // Return true to avoid <Feature Abort> responses. Cec Version is tracked in HdmiCecNetwork.
        return true;
    }

    @ServiceThreadOnly
    protected boolean handleActiveSource(HdmiCecMessage message) {
        return false;
+52 −5
Original line number Diff line number Diff line
@@ -166,7 +166,6 @@ public class HdmiCecNetwork {
        }
        return false;
    }

    /**
     * Clear all logical addresses registered in the device.
     *
@@ -523,8 +522,29 @@ public class HdmiCecNetwork {
            case Constants.MESSAGE_DEVICE_VENDOR_ID:
                handleDeviceVendorId(message);
                break;
            case Constants.MESSAGE_CEC_VERSION:
                handleCecVersion(message);
                break;
            case Constants.MESSAGE_REPORT_FEATURES:
                handleReportFeatures(message);
                break;
        }
    }

    @ServiceThreadOnly
    private void handleReportFeatures(HdmiCecMessage message) {
        assertRunOnServiceThread();

        int version = Byte.toUnsignedInt(message.getParams()[0]);
        updateDeviceCecVersion(message.getSource(), version);
    }

    @ServiceThreadOnly
    private void handleCecVersion(HdmiCecMessage message) {
        assertRunOnServiceThread();

        int version = Byte.toUnsignedInt(message.getParams()[0]);
        updateDeviceCecVersion(message.getSource(), version);
    }

    @ServiceThreadOnly
@@ -543,7 +563,8 @@ public class HdmiCecNetwork {
            HdmiDeviceInfo updatedDeviceInfo = new HdmiDeviceInfo(deviceInfo.getLogicalAddress(),
                    physicalAddress,
                    physicalAddressToPortId(physicalAddress), type, deviceInfo.getVendorId(),
                    deviceInfo.getDisplayName(), deviceInfo.getDevicePowerStatus());
                    deviceInfo.getDisplayName(), deviceInfo.getDevicePowerStatus(),
                    deviceInfo.getCecVersion());
            updateCecDevice(updatedDeviceInfo);
        }
    }
@@ -554,6 +575,31 @@ public class HdmiCecNetwork {
        // Update power status of device
        int newStatus = message.getParams()[0] & 0xFF;
        updateDevicePowerStatus(message.getSource(), newStatus);

        if (message.getDestination() == Constants.ADDR_BROADCAST) {
            updateDeviceCecVersion(message.getSource(), HdmiControlManager.HDMI_CEC_VERSION_2_0);
        }
    }

    @ServiceThreadOnly
    private void updateDeviceCecVersion(int logicalAddress, int hdmiCecVersion) {
        assertRunOnServiceThread();
        HdmiDeviceInfo deviceInfo = getCecDeviceInfo(logicalAddress);
        if (deviceInfo == null) {
            Slog.w(TAG, "Can not update CEC version of non-existing device:" + logicalAddress);
            return;
        }

        if (deviceInfo.getCecVersion() == hdmiCecVersion) {
            return;
        }

        HdmiDeviceInfo updatedDeviceInfo = new HdmiDeviceInfo(deviceInfo.getLogicalAddress(),
                deviceInfo.getPhysicalAddress(), deviceInfo.getPortId(), deviceInfo.getDeviceType(),
                deviceInfo.getVendorId(),
                deviceInfo.getDisplayName(), deviceInfo.getDevicePowerStatus(),
                hdmiCecVersion);
        updateCecDevice(updatedDeviceInfo);
    }

    @ServiceThreadOnly
@@ -586,7 +632,7 @@ public class HdmiCecNetwork {
        updateCecDevice(new HdmiDeviceInfo(deviceInfo.getLogicalAddress(),
                deviceInfo.getPhysicalAddress(), deviceInfo.getPortId(),
                deviceInfo.getDeviceType(), deviceInfo.getVendorId(), osdName,
                deviceInfo.getDevicePowerStatus()));
                deviceInfo.getDevicePowerStatus(), deviceInfo.getCecVersion()));
    }

    @ServiceThreadOnly
@@ -602,7 +648,8 @@ public class HdmiCecNetwork {
            HdmiDeviceInfo updatedDeviceInfo = new HdmiDeviceInfo(deviceInfo.getLogicalAddress(),
                    deviceInfo.getPhysicalAddress(),
                    deviceInfo.getPortId(), deviceInfo.getDeviceType(), vendorId,
                    deviceInfo.getDisplayName(), deviceInfo.getDevicePowerStatus());
                    deviceInfo.getDisplayName(), deviceInfo.getDevicePowerStatus(),
                    deviceInfo.getCecVersion());
            updateCecDevice(updatedDeviceInfo);
        }
    }
+5 −4
Original line number Diff line number Diff line
@@ -813,7 +813,7 @@ public class HdmiControlService extends SystemService {
                                // with system.
                                HdmiDeviceInfo deviceInfo = createDeviceInfo(logicalAddress,
                                        deviceType,
                                        HdmiControlManager.POWER_STATUS_ON);
                                        HdmiControlManager.POWER_STATUS_ON, getCecVersion());
                                localDevice.setDeviceInfo(deviceInfo);
                                mHdmiCecNetwork.addLocalDevice(deviceType, localDevice);
                                mCecController.addLogicalAddress(logicalAddress);
@@ -1222,11 +1222,12 @@ public class HdmiControlService extends SystemService {
        }
    }

    private HdmiDeviceInfo createDeviceInfo(int logicalAddress, int deviceType, int powerStatus) {
    private HdmiDeviceInfo createDeviceInfo(int logicalAddress, int deviceType, int powerStatus,
            int cecVersion) {
        String displayName = readStringSetting(Global.DEVICE_NAME, Build.MODEL);
        return new HdmiDeviceInfo(logicalAddress,
                getPhysicalAddress(), pathToPortId(getPhysicalAddress()), deviceType,
                getVendorId(), displayName, powerStatus);
                getVendorId(), displayName, powerStatus, cecVersion);
    }

    // Set the display name in HdmiDeviceInfo of the current devices to content provided by
@@ -1240,7 +1241,7 @@ public class HdmiControlService extends SystemService {
            device.setDeviceInfo(new HdmiDeviceInfo(
                    deviceInfo.getLogicalAddress(), deviceInfo.getPhysicalAddress(),
                    deviceInfo.getPortId(), deviceInfo.getDeviceType(), deviceInfo.getVendorId(),
                    newDisplayName, deviceInfo.getDevicePowerStatus()));
                    newDisplayName, deviceInfo.getDevicePowerStatus(), deviceInfo.getCecVersion()));
            sendCecCommand(HdmiCecMessageBuilder.buildSetOsdNameCommand(
                    device.mAddress, Constants.ADDR_TV, newDisplayName));
        }
Loading