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

Unverified Commit b4527e8c authored by Sai Priyanka Thirukkovela's avatar Sai Priyanka Thirukkovela Committed by Michael Bestas
Browse files

WiredAccessoryManager: support for DP/HDMI display on soc:qcom,msm-ext-disp.

- Create API setControllerIdx to set the controller index based on the
  interface which was selected.
- Map device index to stream and cable index to controller for HDMI
  ports.
- Use state value to during UEvent handling to connect to DP or HDMI
  respectively.

CRs-Fixed: 3489283

Change-Id: I57bc66fb92bfd0f4125dc91cf7454bc892ad2bed
parent fb31d70b
Loading
Loading
Loading
Loading
+42 −6
Original line number Diff line number Diff line
@@ -73,13 +73,19 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
    private static final String NAME_DP_AUDIO = "soc:qcom,msm-ext-disp";
    // within a device, a single stream supports DP
    private static final String[] DP_AUDIO_CONNS = {
            NAME_DP_AUDIO + "/3/1",
            NAME_DP_AUDIO + "/2/1",
            NAME_DP_AUDIO + "/1/1",
            NAME_DP_AUDIO + "/0/1",
            NAME_DP_AUDIO + "/3/0",
            NAME_DP_AUDIO + "/2/0",
            NAME_DP_AUDIO + "/1/0",
            NAME_DP_AUDIO + "/0/0"
    };
    private static final String NAME_HDMI = "hdmi";

    private static final String NAME_HDMI = "hdmi";
    private static final String INTF_DP = "DP";
    private static final String INTF_HDMI = "HDMI";
    private static final int MSG_NEW_DEVICE_STATE = 1;
    private static final int MSG_SYSTEM_READY = 2;

@@ -90,7 +96,7 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {

    private int mHeadsetState;
    private int mDpCount;

    private String mDetectedIntf = INTF_DP;
    private int mSwitchValues;

    private final WiredAccessoryObserver mObserver;
@@ -400,6 +406,7 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {

    class WiredAccessoryObserver extends UEventObserver {
        private final List<UEventInfo> mUEventInfo;
        private List<String> mDevPath = new ArrayList<String>();

        public WiredAccessoryObserver() {
            mUEventInfo = makeObservedUEventList();
@@ -414,12 +421,17 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
                    UEventInfo uei = mUEventInfo.get(i);
                    try {
                        int curState;
                        FileReader file = new FileReader(uei.getSwitchStatePath());
                        String switchStatePath = uei.getSwitchStatePath();
                        FileReader file = new FileReader(switchStatePath);
                        int len = file.read(buffer, 0, 1024);
                        file.close();
                        curState = Integer.parseInt((new String(buffer, 0, len)).trim());

                        if (curState > 0) {
                            int index = switchStatePath.lastIndexOf(".");
                            if (switchStatePath.substring(index + 1, index + 2).equals("1")) {
                                mDetectedIntf = INTF_HDMI;
                            }
                            updateStateLocked(uei.getDevPath(), uei.getDevName(), curState);
                        }
                    } catch (FileNotFoundException e) {
@@ -437,7 +449,13 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
            // observe three UEVENTs
            for (int i = 0; i < mUEventInfo.size(); ++i) {
                UEventInfo uei = mUEventInfo.get(i);
                String devPath = uei.getDevPath();

                if (mDevPath.contains(devPath))
                    continue;

                startObserving("DEVPATH=" + uei.getDevPath());
                mDevPath.add(devPath);
            }
        }

@@ -522,12 +540,15 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
                        if (equals > offset) {
                            String intfName = stateStr.substring(offset, equals);

                            if (intfName.equals("DP")) {
                            if (intfName.equals("DP") || intfName.equals("HDMI")) {
                                state = Integer.parseInt(
                                        stateStr.substring(equals + 1, equals + 2));
                                if (state == 1) {
                                    mDetectedIntf = intfName;
                                    break;
                                }
                            }
                        }

                        offset = equals + 3;
                    }
@@ -578,6 +599,11 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
                    if (state == 1 && mDpCount > 0) {
                        uei.setStreamIndex(mDpCount);
                    }

                    if (state == 1) {
                        int newControllerIdx = (mDetectedIntf.equals(INTF_DP)) ? 0 : 1;
                        uei.setCableIndex(newControllerIdx);
                    }
                    updateLocked(
                            name, uei.getDevAddress(),
                            uei.computeNewHeadsetState(mHeadsetState, state),
@@ -686,7 +712,10 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
                        file.close();

                        String cableName = (new String(buffer, 0, len)).trim();
                        if (cableName.equals("DP") && index == cableIndex) {
                        if (cableName.equals("HDMI") && index == cableIndex) {
                            mCableIndex = index;
                            break;
                        } else if (cableName.equals("DP") && index == cableIndex) {
                            mCableIndex = index;
                            break;
                        } else {
@@ -707,6 +736,13 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
                mDevAddress = allExceptStreamIdx + String.valueOf(streamIndex);
            }

            public void setCableIndex(int cableIndex) {
                int index = mDevAddress.indexOf("=");
                String changeControllerIdx = mDevAddress.substring(0, index + 1) + cableIndex
                        + mDevAddress.substring(index + 2);
                mDevAddress = changeControllerIdx;
            }

            public String getDevName() {
                return mDevName;
            }