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

Commit a00e1184 authored by Amy's avatar Amy Committed by shubang
Browse files

Change the pathToPort(int path) method in HdmiControlService to apply to

not only TV device.

ag/5297399

The original logic only correct when the device physical address is
0x0000. Now change it to be able to use by any device.

Test: local tested.
Change-Id: I889b6cdc72a94f1b39ae9f87ac4b3f1a071811f9
parent 59176da5
Loading
Loading
Loading
Loading
+23 −5
Original line number Diff line number Diff line
@@ -755,6 +755,9 @@ public class HdmiControlService extends SystemService {
        mPortInfoMap = new UnmodifiableSparseArray<>(portInfoMap);
        mPortDeviceMap = new UnmodifiableSparseArray<>(portDeviceMap);

        if (mMhlController == null) {
            return;
        }
        HdmiPortInfo[] mhlPortInfo = mMhlController.getPortInfos();
        ArraySet<Integer> mhlSupportedPorts = new ArraySet<Integer>(mhlPortInfo.length);
        for (HdmiPortInfo info : mhlPortInfo) {
@@ -809,13 +812,28 @@ public class HdmiControlService extends SystemService {
    }

    /**
     * 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.
     * Returns the id of HDMI port located at the current device that runs this method.
     *
     * For TV with physical address 0x0000, target device 0x1120, we want port physical address
     * 0x1000 to get the correct port id from {@link #mPortIdMap}. For device with Physical Address
     * 0x2000, target device 0x2420, we want port address 0x24000 to get the port id.
     *
     * <p>Return {@link Constants#INVALID_PORT_ID} if target device does not connect to.
     *
     * @param path the target device's physical address.
     * @return the id of the port that the target device eventually connects to
     * on the current device.
     */
    int pathToPortId(int path) {
        int portAddress = path & Constants.ROUTING_PATH_TOP_MASK;
        int mask = 0xF000;
        int finalMask = 0xF000;
        int physicalAddress = getPhysicalAddress();
        while (physicalAddress != 0) {
            physicalAddress &= mask;
            mask >>= 4;
            finalMask |= mask;
        }
        int portAddress = path & finalMask;
        return mPortIdMap.get(portAddress, Constants.INVALID_PORT_ID);
    }

+12 −3
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ final class FakeNativeWrapper implements NativeWrapper {

    private final List<HdmiCecMessage> mResultMessages = new ArrayList<>();
    private int mMyPhysicalAddress = 0;
    private HdmiPortInfo[] mHdmiPortInfo = null;

    @Override
    public long nativeInit(HdmiCecController handler, MessageQueue messageQueue) {
@@ -92,9 +93,11 @@ final class FakeNativeWrapper implements NativeWrapper {

    @Override
    public HdmiPortInfo[] nativeGetPortInfos(long controllerPtr) {
        HdmiPortInfo[] hdmiPortInfo = new HdmiPortInfo[1];
        hdmiPortInfo[0] = new HdmiPortInfo(1, 1, 0x1000, true, true, true);
        return hdmiPortInfo;
        if (mHdmiPortInfo == null) {
            mHdmiPortInfo = new HdmiPortInfo[1];
            mHdmiPortInfo[0] = new HdmiPortInfo(1, 1, 0x1000, true, true, true);
        }
        return mHdmiPortInfo;
    }

    @Override
@@ -131,4 +134,10 @@ final class FakeNativeWrapper implements NativeWrapper {
    protected void setPhysicalAddress(int physicalAddress) {
        mMyPhysicalAddress = physicalAddress;
    }

    @VisibleForTesting
    protected void setPortInfo(HdmiPortInfo[] hdmiPortInfo) {
        mHdmiPortInfo = new HdmiPortInfo[hdmiPortInfo.length];
        System.arraycopy(hdmiPortInfo, 0, mHdmiPortInfo, 0, hdmiPortInfo.length);
    }
}
+32 −0
Original line number Diff line number Diff line
@@ -20,13 +20,18 @@ import static android.hardware.hdmi.HdmiDeviceInfo.DEVICE_PLAYBACK;

import static com.android.server.hdmi.HdmiControlService.INITIATED_BY_ENABLE_CEC;

import static com.google.common.truth.Truth.assertThat;

import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;

import android.hardware.hdmi.HdmiPortInfo;
import android.os.Looper;
import android.os.test.TestLooper;

import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -102,6 +107,7 @@ public class HdmiControlServiceTest {
    private TestLooper mTestLooper = new TestLooper();
    private ArrayList<HdmiCecLocalDevice> mLocalDevices = new ArrayList<>();
    private boolean mStandbyMessageReceived;
    private HdmiPortInfo[] mHdmiPortInfo;

    @Before
    public void SetUp() {
@@ -131,6 +137,12 @@ public class HdmiControlServiceTest {

        mLocalDevices.add(mMyAudioSystemDevice);
        mLocalDevices.add(mMyPlaybackDevice);
        mHdmiPortInfo = new HdmiPortInfo[2];
        mHdmiPortInfo[0] =
            new HdmiPortInfo(1, HdmiPortInfo.PORT_INPUT, 0x2100, true, false, false);
        mHdmiPortInfo[1] =
            new HdmiPortInfo(2, HdmiPortInfo.PORT_INPUT, 0x2200, true, false, false);
        mNativeWrapper.setPortInfo(mHdmiPortInfo);
        mHdmiControlService.initPortInfo();
        mHdmiControlService.allocateLogicalAddress(mLocalDevices, INITIATED_BY_ENABLE_CEC);

@@ -159,4 +171,24 @@ public class HdmiControlServiceTest {
        assertTrue(mMyPlaybackDevice.isDisabled());
        assertTrue(mMyAudioSystemDevice.isDisabled());
    }

    @Test
    public void pathToPort_pathExists_weAreNonTv() {
        mNativeWrapper.setPhysicalAddress(0x2000);
        assertThat(mHdmiControlService.pathToPortId(0x2120)).isEqualTo(1);
        assertThat(mHdmiControlService.pathToPortId(0x2234)).isEqualTo(2);
    }

    @Test
    public void pathToPort_pathExists_weAreTv() {
        mNativeWrapper.setPhysicalAddress(0x0000);
        assertThat(mHdmiControlService.pathToPortId(0x2120)).isEqualTo(2);
        assertThat(mHdmiControlService.pathToPortId(0x1234)).isEqualTo(1);
    }

    @Test
    public void pathToPort_pathInvalid() {
        mNativeWrapper.setPhysicalAddress(0x2000);
        assertThat(mHdmiControlService.pathToPortId(0x1000)).isEqualTo(Constants.INVALID_PORT_ID);
    }
}