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

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

Merge "CEC: Replace the usage of logical address with id for HdmiDeviceInfo" into lmp-dev

parents 5e8abf8e 8960d1b1
Loading
Loading
Loading
Loading
+66 −17
Original line number Diff line number Diff line
@@ -77,11 +77,18 @@ public class HdmiDeviceInfo implements Parcelable {
    /** Invalid port ID */
    public static final int PORT_INVALID = -1;

    private static final int HDMI_DEVICE_TYPE_OTHER = 0;
    private static final int HDMI_DEVICE_TYPE_CEC = 1;
    private static final int HDMI_DEVICE_TYPE_MHL = 2;
    private static final int HDMI_DEVICE_TYPE_CEC = 0;
    private static final int HDMI_DEVICE_TYPE_MHL = 1;
    private static final int HDMI_DEVICE_TYPE_HARDWARE = 2;

    // Offset used for id value. MHL devices, for instance, will be assigned the value from
    // ID_OFFSET_MHL.
    private static final int ID_OFFSET_CEC = 0x0;
    private static final int ID_OFFSET_MHL = 0x80;
    private static final int ID_OFFSET_HARDWARE = 0xC0;

    // Common parameters for all device.
    private final int mId;
    private final int mHdmiDeviceType;
    private final int mPhysicalAddress;
    private final int mPortId;
@@ -121,7 +128,7 @@ public class HdmiDeviceInfo implements Parcelable {
                            int deviceId = source.readInt();
                            int adopterId = source.readInt();
                            return new HdmiDeviceInfo(physicalAddress, portId, adopterId, deviceId);
                        case HDMI_DEVICE_TYPE_OTHER:
                        case HDMI_DEVICE_TYPE_HARDWARE:
                            return new HdmiDeviceInfo(physicalAddress, portId);
                        default:
                            return null;
@@ -152,6 +159,7 @@ public class HdmiDeviceInfo implements Parcelable {
        mPhysicalAddress = physicalAddress;
        mPortId = portId;

        mId = idForCecDevice(logicalAddress);
        mLogicalAddress = logicalAddress;
        mDeviceType = deviceType;
        mVendorId = vendorId;
@@ -180,17 +188,18 @@ public class HdmiDeviceInfo implements Parcelable {
    }

    /**
     * Constructor. Used to initialize the instance for other device.
     * Constructor. Used to initialize the instance for device representing hardware port.
     *
     * @param physicalAddress physical address of HDMI device
     * @param physicalAddress physical address of the port
     * @param portId HDMI port ID (1 for HDMI1)
     * @hide
     */
    public HdmiDeviceInfo(int physicalAddress, int portId) {
        mHdmiDeviceType = HDMI_DEVICE_TYPE_OTHER;
        mHdmiDeviceType = HDMI_DEVICE_TYPE_HARDWARE;
        mPhysicalAddress = physicalAddress;
        mPortId = portId;

        mId = idForHardware(portId);
        mLogicalAddress = -1;
        mDeviceType = DEVICE_RESERVED;
        mVendorId = 0;
@@ -216,6 +225,7 @@ public class HdmiDeviceInfo implements Parcelable {
        mPhysicalAddress = physicalAddress;
        mPortId = portId;

        mId = idForMhlDevice(portId);
        mLogicalAddress = -1;
        mDeviceType = DEVICE_RESERVED;
        mVendorId = 0;
@@ -226,6 +236,45 @@ public class HdmiDeviceInfo implements Parcelable {
        mAdopterId = deviceId;
    }

    /**
     * Return the id of the device.
     */
    public int getId() {
        return mId;
    }

    /**
     * Return the id to be used for CEC device.
     *
     * @param address logical address of CEC device
     * @return id for CEC device
     */
    public static int idForCecDevice(int address) {
        // The id is generated based on the logical address.
        return ID_OFFSET_CEC + address;
    }

    /**
     * Return the id to be used for MHL device.
     *
     * @param portId port which the MHL device is connected to
     * @return id for MHL device
     */
    public static int idForMhlDevice(int portId) {
        // The id is generated based on the port id since there can be only one MHL device per port.
        return ID_OFFSET_MHL + portId;
    }

    /**
     * Return the id to be used for hardware port.
     *
     * @param portId port id
     * @return id for hardware port
     */
    public static int idForHardware(int portId) {
        return ID_OFFSET_HARDWARE + portId;
    }

    /**
     * Return the CEC logical address of the device.
     */
@@ -367,25 +416,25 @@ public class HdmiDeviceInfo implements Parcelable {
        switch (mHdmiDeviceType) {
            case HDMI_DEVICE_TYPE_CEC:
                s.append("CEC: ");
                s.append("logical_address: ").append(mLogicalAddress).append(", ");
                s.append("device_type: ").append(mDeviceType).append(", ");
                s.append("vendor_id: ").append(mVendorId).append(", ");
                s.append("display_name: ").append(mDisplayName).append(", ");
                s.append("power_status: ").append(mDevicePowerStatus).append(", ");
                s.append("logical_address: ").append(mLogicalAddress).append(" ");
                s.append("device_type: ").append(mDeviceType).append(" ");
                s.append("vendor_id: ").append(mVendorId).append(" ");
                s.append("display_name: ").append(mDisplayName).append(" ");
                s.append("power_status: ").append(mDevicePowerStatus).append(" ");
                break;
            case HDMI_DEVICE_TYPE_MHL:
                s.append("MHL: ");
                s.append("device_id: ").append(mDeviceId).append(" ");
                s.append("adopter_id: ").append(mAdopterId).append(" ");
                break;

            case HDMI_DEVICE_TYPE_OTHER:
                s.append("Other: ");
                s.append("device_id: ").append(mDeviceId).append(", ");
                s.append("adopter_id: ").append(mAdopterId).append(", ");
            case HDMI_DEVICE_TYPE_HARDWARE:
                s.append("Hardware: ");
                break;
            default:
                return "";
        }
        s.append("physical_address: ").append(mPhysicalAddress).append(", ");
        s.append("physical_address: ").append(String.format("0x04X", mPhysicalAddress)).append(" ");
        s.append("port_id: ").append(mPortId);
        return s.toString();
    }
+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ interface IHdmiControlService {
    void addHotplugEventListener(IHdmiHotplugEventListener listener);
    void removeHotplugEventListener(IHdmiHotplugEventListener listener);
    void addDeviceEventListener(IHdmiDeviceEventListener listener);
    void deviceSelect(int logicalAddress, IHdmiControlCallback callback);
    void deviceSelect(int deviceId, IHdmiControlCallback callback);
    void portSelect(int portId, IHdmiControlCallback callback);
    void sendKeyEvent(int deviceType, int keyCode, boolean isPressed);
    List<HdmiPortInfo> getPortInfo();
+1 −1
Original line number Diff line number Diff line
@@ -25,6 +25,6 @@ import android.media.tv.TvInputInfo;
 */
oneway interface ITvInputServiceCallback {
    void addHardwareTvInput(in int deviceId, in TvInputInfo inputInfo);
    void addHdmiTvInput(in int logicalAddress, in TvInputInfo inputInfo);
    void addHdmiTvInput(in int id, in TvInputInfo inputInfo);
    void removeTvInput(in String inputId);
}
+3 −3
Original line number Diff line number Diff line
@@ -113,7 +113,7 @@ public final class TvInputInfo implements Parcelable {
    private static final String PREFIX_HDMI_DEVICE = "HDMI";
    private static final String PREFIX_HARDWARE_DEVICE = "HW";
    private static final int LENGTH_HDMI_PHYSICAL_ADDRESS = 4;
    private static final int LENGTH_HDMI_LOGICAL_ADDRESS = 2;
    private static final int LENGTH_HDMI_DEVICE_ID = 2;

    private final ResolveInfo mService;
    private final String mId;
@@ -537,9 +537,9 @@ public final class TvInputInfo implements Parcelable {
            ComponentName name, HdmiDeviceInfo deviceInfo) {
        // Example of the format : "/HDMI%04X%02X"
        String format = String.format("%s%s%%0%sX%%0%sX", DELIMITER_INFO_IN_ID, PREFIX_HDMI_DEVICE,
                LENGTH_HDMI_PHYSICAL_ADDRESS, LENGTH_HDMI_LOGICAL_ADDRESS);
                LENGTH_HDMI_PHYSICAL_ADDRESS, LENGTH_HDMI_DEVICE_ID);
        return name.flattenToShortString() + String.format(format,
                deviceInfo.getPhysicalAddress(), deviceInfo.getLogicalAddress());
                deviceInfo.getPhysicalAddress(), deviceInfo.getId());
    }

    /**
+4 −4
Original line number Diff line number Diff line
@@ -213,7 +213,7 @@ public abstract class TvInputService extends Service {
    }

    /**
     * Returns the input ID for {@code logicalAddress} if it is handled by this service; otherwise,
     * Returns the input ID for {@code deviceInfo} if it is handled by this service; otherwise,
     * return {@code null}. Override to modify default behavior of ignoring all HDMI logical input
     * device.
     *
@@ -1178,11 +1178,11 @@ public abstract class TvInputService extends Service {
            mCallbacks.finishBroadcast();
        }

        private void broadcastAddHdmiTvInput(int logicalAddress, TvInputInfo inputInfo) {
        private void broadcastAddHdmiTvInput(int id, TvInputInfo inputInfo) {
            int n = mCallbacks.beginBroadcast();
            for (int i = 0; i < n; ++i) {
                try {
                    mCallbacks.getBroadcastItem(i).addHdmiTvInput(logicalAddress, inputInfo);
                    mCallbacks.getBroadcastItem(i).addHdmiTvInput(id, inputInfo);
                } catch (RemoteException e) {
                    Log.e(TAG, "Error while broadcasting.", e);
                }
@@ -1289,7 +1289,7 @@ public abstract class TvInputService extends Service {
                    HdmiDeviceInfo deviceInfo = (HdmiDeviceInfo) msg.obj;
                    TvInputInfo inputInfo = onHdmiDeviceAdded(deviceInfo);
                    if (inputInfo != null) {
                        broadcastAddHdmiTvInput(deviceInfo.getLogicalAddress(), inputInfo);
                        broadcastAddHdmiTvInput(deviceInfo.getId(), inputInfo);
                    }
                    return;
                }
Loading