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

Commit 401e3de7 authored by Jinsuk Kim's avatar Jinsuk Kim
Browse files

Add methods in HdmiControlService fort port_id/path conversion

Use HdmiPortInfo list to get the port ID from a given routing path,
and vice versa. This is useful when you need to get the HDMI port
to which a certain device is attached in its hierarchy by its routing
path.

Change-Id: If1e7e8fdd005671d4e1fbb04dc26b24885320a92
parent 2110ca32
Loading
Loading
Loading
Loading
+37 −4
Original line number Diff line number Diff line
@@ -138,7 +138,8 @@ public final class HdmiControlService extends SystemService {
    private int mActiveSource;

    // Active routing path. Physical address of the active source but not all the time, such as
    // when the new active source does not claim itself to be one.
    // when the new active source does not claim itself to be one. Note that we don't keep
    // the active port id (or active input) since it can be gotten by {@link #pathToPortId(int)}.
    @GuardedBy("mLock")
    private int mActiveRoutingPath;

@@ -287,6 +288,35 @@ public final class HdmiControlService extends SystemService {
        return null;
    }

    /**
     * Returns the routing path (physical address) of the HDMI port for the given
     * port id.
     */
    int portIdToPath(int portId) {
        HdmiPortInfo portInfo = getPortInfo(portId);
        if (portInfo == null) {
            Slog.e(TAG, "Cannot find the port info: " + portId);
            return 0xFFFF;  // Use HdmiConstants.INVALID_PHYSICAL_ADDRESS;
        }
        return portInfo.getAddress();
    }

    /**
     * Returns the id of HDMI port located at the top of the hierarchy of
     * the specified routing path. For the routing path 0x1220 (1.2.2.0), for instance,
     * the port id to be returned is the ID associated with the port address
     * 0x1000 (1.0.0.0) which is the topmost path of the given routing path.
     */
    int pathToPortId(int path) {
        int portAddress = path & HdmiConstants.ROUTING_PATH_TOP_MASK;
        for (HdmiPortInfo info : mPortInfo) {
            if (portAddress == info.getAddress()) {
                return info.getId();
            }
        }
        return -1;  // Use HdmiConstants.INVALID_PORT_ID;
    }

    /**
     * Returns {@link Looper} for IO operation.
     *
@@ -312,6 +342,9 @@ public final class HdmiControlService extends SystemService {
        }
    }

    /**
     * Returns the active routing path.
     */
    int getActivePath() {
        synchronized (mLock) {
            return mActiveRoutingPath;
@@ -319,12 +352,12 @@ public final class HdmiControlService extends SystemService {
    }

    /**
     * Returns the path (physical address) of the device at the top of the currently active
     * routing path. Used to get the corresponding port address of the HDMI input of the TV.
     * Returns the ID of the active HDMI port. The active input is the port that has the active
     * routing path connected directly or indirectly under the device hierarchy.
     */
    int getActiveInput() {
        synchronized (mLock) {
            return mActiveRoutingPath & HdmiConstants.ROUTING_PATH_TOP_MASK;
            return pathToPortId(mActiveRoutingPath);
        }
    }

+8 −13
Original line number Diff line number Diff line
@@ -64,11 +64,11 @@ public class RoutingControlAction extends FeatureAction {
    // The latest routing path. Updated by each <Routing Information> from CEC switches.
    private int mCurrentRoutingPath;

    RoutingControlAction(HdmiControlService service, int sourceAddress, int portId,
    RoutingControlAction(HdmiControlService service, int sourceAddress, int path,
            IHdmiControlCallback callback) {
        super(service, sourceAddress);
        mCallback = callback;
        mCurrentRoutingPath = portToPath(portId);
        mCurrentRoutingPath = path;
    }

    @Override
@@ -86,7 +86,7 @@ public class RoutingControlAction extends FeatureAction {
                && opcode == HdmiCec.MESSAGE_ROUTING_INFORMATION) {
            // Keep updating the physicalAddress as we receive <Routing Information>.
            // If the routing path doesn't belong to the currently active one, we should
            // ignore it since it might have come from other, routing change sequence.
            // ignore it since it might have come from other routing change sequence.
            int routingPath = HdmiUtils.twoBytesToInt(params);
            if (isInActiveRoutingPath(mCurrentRoutingPath, routingPath)) {
                return true;
@@ -167,7 +167,7 @@ public class RoutingControlAction extends FeatureAction {
            case STATE_WAIT_FOR_ROUTING_INFORMATION:
                HdmiCecDeviceInfo device = mService.getDeviceInfoByPath(mCurrentRoutingPath);
                if (device == null) {
                    maybeChangeActiveInput(pathToPort(mCurrentRoutingPath));
                    maybeChangeActiveInput(mCurrentRoutingPath);
                } else {
                    // TODO: Also check followings and then proceed:
                    //       if routing change was neither triggered by TV at CEC enable time, nor
@@ -185,7 +185,7 @@ public class RoutingControlAction extends FeatureAction {
            case STATE_WAIT_FOR_REPORT_POWER_STATUS:
                int tvPowerStatus = getTvPowerStatus();
                if (isPowerStatusOnOrTransientToOn(tvPowerStatus)) {
                    if (!maybeChangeActiveInput(pathToPort(mCurrentRoutingPath))) {
                    if (!maybeChangeActiveInput(mCurrentRoutingPath)) {
                        sendSetStreamPath();
                    }
                }
@@ -196,8 +196,8 @@ public class RoutingControlAction extends FeatureAction {
    }

    // Called whenever an HDMI input of the TV shall become the active input.
    private boolean maybeChangeActiveInput(int inputPortPath) {
        if (mService.getActiveInput() == inputPortPath) {
    private boolean maybeChangeActiveInput(int path) {
        if (mService.getActiveInput() == mService.pathToPortId(path)) {
            return false;
        }
        // TODO: Remember the currently active input
@@ -217,15 +217,10 @@ public class RoutingControlAction extends FeatureAction {
            mState = STATE_WAIT_FOR_REPORT_POWER_STATUS;
            addTimer(mState, TIMEOUT_REPORT_POWER_STATUS_MS);
        } else {
            maybeChangeActiveInput(pathToPort(mCurrentRoutingPath));
            maybeChangeActiveInput(mCurrentRoutingPath);
        }
    }

    // Get the address of the TV port to which the given path is connected.
    private static int pathToPort(int path) {
        return path & HdmiConstants.ROUTING_PATH_TOP_MASK;
    }

    // Given the HDMI port id, return the port address.
    private int portToPath(int portId) {
        return mService.getPortInfo(portId).getAddress();